以前的備注,今天翻出來寫個博客記錄一下, RecyclerView的item布局設(shè)置match_parent經(jīng)常不起作用,可以在代碼中填充布局時這樣寫:
@Override
public Main2ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new Main2ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item,parent,false));
}
因?yàn)樵创a中有如下內(nèi)容
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);
}
}