【问题标题】:Having a whitespace issue with Recyclerview inside Scrolling Activity滚动活动中的 Recyclerview 存在空白问题
【发布时间】:2016-08-29 13:31:17
【问题描述】:

我在滚动活动中的 Recyclerview 中遇到了空白问题。 请帮我解决这个问题。我已经检查了我所知道的所有内容,例如没有边距、填充,通过删除 FAB 进行了尝试。但问题依然存在。

我的 XML 代码:

   <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
   >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/id_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end" />

</android.support.design.widget.CoordinatorLayout>

【问题讨论】:

  • 发布你完整的xml代码,我可以看到一些部分丢失
  • 对我来说,您从 AppBarLayout 的高度看起来比内容大,并且出现空白。用包装内容替换它
  • 对,确保你的布局有合适的高度。对我来说,它看起来像错过了状态栏的大小。检查如果从 CoordinatorLayout 中删除“fitsSystemWindows”会发生什么。将其保留在 AppBar 中。
  • 您提到的代码似乎没问题。需要检查 RecyclerView 的列表项布局。
  • 这个问题发生在appbar和recycler之间,好像和wxh没有关系

标签: android android-recyclerview android-appbarlayout


【解决方案1】:

删除android:fitsSystemWindows="true"android:layout_height="wrap_content" 试试这个

<android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

【讨论】:

  • 如果我输入android:layout_height="wrap_content",应用栏就会消失。
  • 您是否尝试删除android:fitsSystemWindows="true",然后放入android:layout_height="wrap_content"
【解决方案2】:

试试这个:

<android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

【讨论】:

    【解决方案3】:

    我终于明白了, 首先感谢TWL在他question的同期给我一个思路。

    我从CoordinatorLayout 中删除了android:fitsSystemWindows="true"

    现在,您的通知栏颜色可能更改为透明,看起来很糟糕。所以,我在样式中添加了&lt;item name="android:statusBarColor" tools:targetApi="lollipop"&gt;@color/colorPrimary&lt;/item&gt;

    现在一切正常。

    【讨论】:

    • 谢谢,但如果您现在注意到,通知栏的颜色可能不是您应用主题颜色的一部分,因为它现在不再“下方”,而是“下方”。
    • @TWL :是的,我也通过在样式中添加 &lt;item name="android:statusBarColor" tools:targetApi="lollipop"&gt;@color/colorPrimary&lt;/item&gt; 来改变它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    • 2023-02-05
    • 2020-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多