使用RecyclerView 时,在xml文件中设置宽度match_parent无效,解决办法如下:
在Adapter中要如下填充view,
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
ViewHolder viewHolder = null;
LayoutInflater mInflater = LayoutInflater.from(mContext);
switch (viewType) {
case FragmentBookShelf.GRID:
View view = mInflater.from(mContext).inflate(R.layout.item_grid_bookshelf, parent, false));
viewHolder = new GridViewHolder(view);
break;
case FragmentBookShelf.LIST:
View view = mInflater.from(mContext).inflate(R.layout.item_list_bookshelf, parent, false));
viewHolder = new ListViewHolder(view);
break;
}
return viewHolder;
}