CollapsingToolbarLayout在RecyclerView滚动上不一致地崩溃



当在RecyclerView中使用CollapsingToolBarLayout时,我发现滚动时工具栏不一致。我可以滚动到循环视图的一半,直到任何东西崩溃,然后它会断断续续地崩溃。这种行为并不总是一致的——有时它会比其他行为更容易崩溃。然而,当我滚动到底部时,它总是完全崩溃。我的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。根据这个答案,在内部RecyclerView上设置setNestedScrollingEnabled(false)会导致事情按照预期的方式运行。

最新更新