RecyclerView中item无法充满的问题

首先致谢:https://blog.csdn.net/yuanlvmao/article/details/51694211

咱们不是代码的生产者,只是代码的搬运工。

今天写了一个RecyclerView,写完后发现有个item居然没有充满 
其中,item的布局是这样的

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3               android:orientation="vertical"
 4               android:layout_width="match_parent"
 5               android:layout_height="wrap_content"
 6     android:background="@color/line_background_e7e7e7">
 7     <TextView
 8         android:id="@+id/tv_introduce"
 9         android:layout_width="match_parent"
10         android:layout_height="wrap_content"
11         android:padding="10dp"
12         android:textColor="#777777"
13         android:text="item11111"
14         android:background="#e7e7e7"/>
15 
16 </LinearLayout>
item 的布局代码

可是,在实际效果中,item并没有充满,match_parent完全没有效果,效果是wrap_content自适应 
后面仔细看了代码,发现是在适配器中加载布局时候的问题 
一开始是这样写的,在onCreateViewHolder()中 
view = View.inflate(mContext, R.layout.item,null); 
return new ViewHolder(view);
 

后面将这代码改成

 1 view = LayoutInflater.from(mContext).inflate(R.layout.item,parent,false); 

就没有出现item显示不全的问题了

记录完毕

以一颗童心善待生活
原文地址:https://www.cnblogs.com/lizhilin2016/p/9132672.html