转载请注明链接:https://blog.youkuaiyun.com/feather_wch/article/details/88293585
试过很多办法,但是都是标题党。本问题绝对可以解决。
RecyclerView 高度 wrap_content 失效的问题
版本:2019-03-07(12:30)
RecyclerView的属性
android:layout_height="wrap_content"出现了失效的问题,我是用的GridLayoutManager,结果只有一行的数据。
该问题是谷歌的BUG
修复方法
1、修复方法
- 用
RelativeLayout包裹RecyclerView,RelativeLayout的高度采用wrap_contentRecyclerView的高度,采用match_parent如下:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/home_videos_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
本文详细介绍了在遇到RecyclerView设置高度为wrap_content时失效的问题,特别是当使用GridLayoutManager且只显示一行数据的情况。作者指出这可能是谷歌的一个BUG,并提供了一个有效的修复方案,通过在RecyclerView外层包裹一个布局,将RecyclerView的高度设置为外层布局的高度来解决问题。
1580

被折叠的 条评论
为什么被折叠?



