Android 当为其提供匹配父项时,Recyclerview项不会占据屏幕的所有宽度

Android 当为其提供匹配父项时,Recyclerview项不会占据屏幕的所有宽度,android,xml,android-layout,Android,Xml,Android Layout,这里是我的问题,而使一个新的回收评论,它显示如下不采取所有宽度 我的活动 我的适配器 这里是activity_reviews.xml 以及列表_item _user _review.xml 我尝试了很多,使所有的布局匹配的家长和它仍然是因为它出现在上面,我搜索的问题,我看到了这一点 在ReviewRVAdapter类的onCreateViewHolder方法中,您有以下代码行: View layoutView = LayoutInflater.from(parent.getContext())

这里是我的问题,而使一个新的回收评论,它显示如下不采取所有宽度

我的活动

我的适配器

这里是activity_reviews.xml

以及列表_item _user _review.xml

我尝试了很多,使所有的布局匹配的家长和它仍然是因为它出现在上面,我搜索的问题,我看到了这一点

在ReviewRVAdapter类的onCreateViewHolder方法中,您有以下代码行:

View layoutView = LayoutInflater.from(parent.getContext())
        .inflate(R.layout.list_item_user_review, null);
现在,在膨胀视图时,将null传递为父级。这使得创建的视图无法与宽度的父视图匹配

改为:

View layoutView = LayoutInflater.from(parent.getContext())
        .inflate(R.layout.list_item_user_review, parent, false);
现在,在膨胀视图时,您将有一个非空的父对象,因此宽度将正确设置。

在ReviewRVAdapter类中,在onCreateViewHolder方法中,您有以下代码行:

View layoutView = LayoutInflater.from(parent.getContext())
        .inflate(R.layout.list_item_user_review, null);
现在,在膨胀视图时,将null传递为父级。这使得创建的视图无法与宽度的父视图匹配

改为:

View layoutView = LayoutInflater.from(parent.getContext())
        .inflate(R.layout.list_item_user_review, parent, false);
现在,在膨胀视图时,将有一个非空的父对象,因此将正确设置宽度

View layoutView = LayoutInflater.from(parent.getContext())
        .inflate(R.layout.list_item_user_review, null);
View layoutView = LayoutInflater.from(parent.getContext())
        .inflate(R.layout.list_item_user_review, parent, false);