您的位置:首页 > 移动开发 > Android开发

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

2017-08-07 12:10 573 查看
今天写了一个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显示不能充满的问题了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息