【问题标题】:Coordinator Layout with 2 Recycler Views具有 2 个回收站视图的协调器布局
【发布时间】:2019-01-10 16:36:22
【问题描述】:
我想用这个布局构建一个 android 片段:
- 屏幕的上半部分是一个水平滚动的 RecyclerView。
- 屏幕的下半部分是一个可垂直滚动的 RecyclerView。
当底部 RecyclerView 向底部滚动时,我希望顶部的 RecyclerView 折叠和隐藏(并在底部视图滚动到顶部时打开)。
协调器布局似乎是答案,但我遇到的每个示例都使用 AppBarLayout 作为顶部。包含该片段的活动已经显示了一个应用栏;我不想修改它。
如何在 CoordinatorLayout 中实现这两个 RecyclerView 设置而不解决应用栏?
【问题讨论】:
标签:
android
android-recyclerview
android-coordinatorlayout
【解决方案1】:
您可以使用NestedScrollView、垂直方向的LinearLayout 作为NestedScrollView 的子级,并将RecyclerViews 添加为LinearLayout 的子级
样本
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>