2017-06-22 88 views
2

根据附图,我正在遇到一个空白区域,在回收站查看项目上方有一个页面高度。
problem illustration of empty gap in recyclerviewAndroid RecyclerView在上述项目上有空白

这里是我的recyclerview排布局:

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

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:background="@color/white"> 

      ... 

     </RelativeLayout> 

    </android.support.v7.widget.CardView> 

</LinearLayout> 

这是我的活动布局:

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


    <include 
     android:id="@+id/list_toolbar" 
     layout="@layout/toolbar_list"></include> 

    <android.support.v7.widget.RecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbars="vertical" /> 

     ... 

我也试过layout_height="match_parent"recyclerview,但唯一的区别是空的差距第一个显示没有任何滚动。
设置项目的固定高度也没有改变任何东西。

回答

1

更新依赖于recyclerview-v7:25.3.1后,我被迫match_parent所有row_itemslayout_height更改为wrap_content
在这种情况下,我忘了更改layout_heightitem_row布局,这是我的header行的recyclerview

这里是我的recyclerview标题行应该有layout_height="wrap_content"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical">