【发布时间】:2020-11-18 14:58:17
【问题描述】:
你好, 下面是我的布局:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/layout_1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/color_dark_red">
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="640dp"
android:background="@color/color_black"
android:layout_below="@+id/layout_1" />
<RelativeLayout
android:id="@+id/layout_2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/recycler_view"
android:background="#0f0">
</RelativeLayout>
</RelativeLayout>
截图下方:
我想在用户向下滚动 recyclerView 时隐藏 layout_1,或者在用户向上滚动 recyclerView 时隐藏 layout_2。
根据文档: 切勿将 RecyclerView 或 ListView 添加到滚动视图。这样做会导致用户界面性能不佳和用户体验不佳。
我也不想使用NestedScrollView,因为它会在background Thread 中更新recyclerView 时禁用(或删除)DiffUtil 工作,如以下问题所示:
如何使recycler_view 的向下滚动隐藏layout_1 并向上滚动隐藏layout_2
不使用 ScrollView 或 NestedScrollView ?
谢谢。
【问题讨论】:
-
在您的情况下,我认为可以在您的 layout_1 和 layout_2 中模拟折叠视图效果。当用户滚动列表时,您可以使用 RecyclerView 侦听器来处理,然后在视图中应用动画来隐藏或显示它们。
标签: android android-layout android-recyclerview android-scrollview android-nestedscrollview