Android RecyclerView 项目上方有空白
Android RecyclerView there is empty gap at the above of the items
根据所附图片,我遇到了一个空白 space,在 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>
这是我的 activity 布局:
<?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" />
...
我也为 recyclerview
尝试了 layout_height="match_parent"
,但唯一的区别是第一个显示的空白间隙没有任何滚动。
为项目设置固定高度也没有改变任何东西。
将依赖项更新为 recyclerview-v7:25.3.1
后,我强制将所有 row_items
的 layout_height
从 match_parent
更改为 wrap_content
。
在这种情况下,我忘记更改 item_row
布局的 layout_height
,这是我 header
行的 recyclerview
。
这是我的 recyclerview
header 行,应该有 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">
根据所附图片,我遇到了一个空白 space,在 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>
这是我的 activity 布局:
<?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" />
...
我也为 recyclerview
尝试了 layout_height="match_parent"
,但唯一的区别是第一个显示的空白间隙没有任何滚动。
为项目设置固定高度也没有改变任何东西。
将依赖项更新为 recyclerview-v7:25.3.1
后,我强制将所有 row_items
的 layout_height
从 match_parent
更改为 wrap_content
。
在这种情况下,我忘记更改 item_row
布局的 layout_height
,这是我 header
行的 recyclerview
。
这是我的 recyclerview
header 行,应该有 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">