在23.2.0之后具有大空白空间的RecyclerView项目

Gab*_*tti 43 android android-support-library android-recyclerview

更新到v23.2.0之后,我的RecyclerView项目之间有巨大的空白垂直空间.

我的项目布局非常简单:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent"                                    
       android:orientation="vertical" >
Run Code Online (Sandbox Code Playgroud)

Gab*_*tti 127

根据文件

在版本23.2.0中,LayoutManager API有一个令人兴奋的新功能:自动测量!
这允许RecyclerView基于其内容的大小来自我调整大小.这意味着现在可以使用以前不可用的方案,例如使用WRAP_CONTENT作为RecyclerView的维度.
您会发现所有内置的LayoutManagers现在都支持自动测量.

由于此更改,请务必仔细检查项目视图的布局参数:现在将完全遵循先前忽略的布局参数(例如滚动方向中的MATCH_PARENT).

在您的项目布局中,您必须更改:

android:layout_height="match_parent"
Run Code Online (Sandbox Code Playgroud)

android:layout_height="wrap_content" 
Run Code Online (Sandbox Code Playgroud)

  • 感谢我的朋友因为意外和反直觉行为而拯救了我一个沮丧的夜晚.布拉沃. (2认同)

Gök*_*ren 14

您必须使Recyclerview和项目布局高度包装内容.


Lee*_*ell 6

在我的情况下,我已经进行了新的wrap_content更改,但在onMove或onSwipe期间仍然存在间隙.我通过添加此代码解决了这个问题:

mRecyclerView.getLayoutManager().setMeasurementCacheEnabled(false);
Run Code Online (Sandbox Code Playgroud)