Android RecyclerView关于item无法充满屏幕的问题

xiaoxiao2021-02-28  89

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

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout>

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

view = layoutInflater.inflate(R.layout.fragment_notice_item,null);

后面将这代码改成

view = layoutInflater.inflate(R.layout.fragment_notice_item,parent,false);

就没有出现item显示不能充满的问题了

转载请注明原文地址: https://www.6miu.com/read-83811.html

最新回复(0)