以前的备注,今天翻出来写个博客记录一下, RecyclerView的item布局设置match_parent经常不起作用,可以在代码中填充布局时这样写:
@Override
public Main2ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new Main2ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item,parent,false));
}
因为源码中有如下内容
if (root != null) {
if (DEBUG) {
System.out.println("Creating params from root: " +
root);
}
// Create layout params that match root, if supplied
params = root.generateLayoutParams(attrs);
if (!attachToRoot) {
// Set the layout params for temp if we are not
// attaching. (If we are, we use addView, below)
temp.setLayoutParams(params);
}
}
网友评论