【问题标题】:Android Design Support Library: RecyclerView animating up in a CoordinatorLayoutAndroid 设计支持库:在 CoordinatorLayout 中动画化的 RecyclerView
【发布时间】:2015-07-24 21:45:59
【问题描述】:

我正在使用最新版本的设计支持库,但遇到了问题。在包含 CollpasingToolbarLayout 和 RecyclerView 的协调器布局中,RecyclerView 有时会向上设置状态栏的高度。我确定这与此视图使用“fitsSystemWindows”xml 属性隐藏状态栏这一事实有关。

这里是发生了什么的屏幕:

如您所见,RecyclerView 底部有一个不应该存在的边距。

这是 XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:bit="http://schemas.android.com/apk/res-auto"
    android:id="@+id/root"
    android:background="@color/activity_background_color"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <include layout="@layout/toolbar_image"/>

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

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

“toolbar_image”是这个视图:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
    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:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/toolbar_backdrop_height"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/actionbar_body_color"
        app:expandedTitleMarginStart="@dimen/toolbar_title_left_margin"
        app:collapsedTitleTextAppearance="@style/Widget.Bandsintown.ToolbarTitleTextAppearance"
        app:expandedTitleMarginBottom="@dimen/toolbar_title_bottom_margin">

        <ImageView
            android:id="@+id/toolbar_backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:transitionName="@string/transition_image"
            app:layout_collapseMode="parallax"
            tools:ignore="UnusedAttribute" />

        <View
            android:id="@+id/toolbar_bottom_gradient"
            android:layout_width="match_parent"
            android:layout_height="@dimen/toolbar_height"
            android:layout_gravity="bottom"
            android:background="@drawable/dark_gradient_ascending"/>

        <View
            android:id="@+id/toolbar_top_gradient"
            android:layout_width="match_parent"
            android:layout_height="@dimen/toolbar_height"
            android:layout_gravity="top"
            android:fitsSystemWindows="true"
            android:background="@drawable/dark_gradient_descending"/>

        <TextView
            android:id="@+id/toolbar_subtitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/toolbar_title_left_margin"
            android:layout_marginBottom="12dp"
            android:textColor="@android:color/white"
            android:layout_gravity="bottom"
            style="@style/Widget.Bandsintown.ToolbarSubtitleTextAppearance"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/toolbar_height"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin" />

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

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

我还录制了正在发生的事情的视频。在这个剪辑中,它需要几次尝试才能实现,因此您可以先查看它应该做什么,然后再查看错误。

这里是链接:https://dl.dropboxusercontent.com/u/97787025/device-2015-07-24-143017.mp4

在我在其他地方使用的与 NestedScrollView 一起使用的 CoordinatorLayout 中不会发生同样的问题。对此的任何帮助将不胜感激,我感觉它是一个库错误,但如果有修复,请告诉我。谢谢!

【问题讨论】:

    标签: android


    【解决方案1】:

    我最近遇到了一个非常相似的问题。我不知道如何解决它,但也许详细分享我的问题可以帮助其他人更好地解决您的问题:

    1. 您是否尝试过将支持库切换到旧版本?只有在使用支持库 24.0.0 或更高版本时,我才会得到您的错误。

    2. 您是否使用嵌套的回收视图?经过几次测试,我发现我的错误只有在我停止滚动时才会出现,或者显示包含我的 out recyclerview 的片段(尽管您在这里没有使用片段)并且部分显示了嵌套的 recyclerview。然后外部 recyclerview 会自动滚动到屏幕上嵌套 recyclerview 的顶部或底部。

    【讨论】:

      猜你喜欢
      • 2015-09-22
      • 2015-12-13
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2015-08-13
      • 2016-12-29
      • 2015-08-23
      • 2015-09-23
      相关资源
      最近更新 更多