RecyclerView android:layout_width="match_parent"无效解决方法

使用RecyclerView 时,在xml文件中设置宽度match_parent无效,发现在Adapter中要如下填充view(注释掉的填充方式会导致match_parent无效)

/**
* 创建新View,被LayoutManager所调用
*/
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// View view = View.inflate(parent.getContext(), R.layout.item_fra_main2, null);
View view = mInflater.from(mContext).inflate(R.layout.item_fra_main2, parent, false);
ViewHolder holder = new ViewHolder(view);
return holder;
}
原理请看

Android编程之LayoutInflater的inflate方法详解

你可能感兴趣的:(零碎小知识)