如何解决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)
会导致事情按预期运行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。