CollapsingToolbarLayout 在 RecyclerView 滚动上不一致地折叠

问题描述

使用带有 RecyclerView 的 CollapsingToolBarLayout 时,我发现工具栏在滚动时折叠不一致。在任何东西崩溃之前,我可以在 recyclerview 中滚动大约一半,然后它会断断续续地崩溃。这种行为并不总是一致的——有时它会比其他人崩溃得更多。然而,当我滚动到底部时,它总是完全折叠。我的 XML 如下所示:

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true" >
        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true">
            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:fitsSystemWindows="true"
                app:layout_scrollFlags="scroll|enteralways|enteralwaysCollapsed" >
                <com.google.android.material.appbar.MaterialToolbar
                    android:layout_height="?attr/actionBarSize"
                    android:layout_width="match_parent"
                    app:layout_collapseMode="pin" />
            </com.google.android.material.appbar.CollapsingToolbarLayout>
        </com.google.android.material.appbar.AppBarLayout>
        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

解决方法

事实证明,最终的问题是在第一个的一些视图持有者中拥有第二个 RecyclerView。根据 this answer,在内部 RecyclerView 上设置 setNestedScrollingEnabled(false) 会导致事情按预期运行。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...