具有 2 个回收器视图的协调器布局
Coordinator Layout with 2 Recycler Views
我想用这种布局构建一个 android 片段:
- 屏幕的上半部分是水平滚动的 RecyclerView。
- 屏幕的下半部分是一个垂直滚动的 RecyclerView。
当底部的 RecyclerView 向底部滚动时,我希望顶部的 RecyclerView 折叠并隐藏(当底部视图滚动到顶部时打开)。
协调器布局似乎是答案,但我遇到的每个示例都在顶部使用 AppBarLayout。包含片段的 activity 已经显示了应用栏;我不想修改它。
如何在 CoordinatorLayout 中实现这两个 RecyclerView 设置而不处理应用栏?
您可以使用 NestedScrollView
、垂直方向的 LinearLayout
作为 NestedScrollView
的子项,并将两个 RecyclerView
添加为 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>
我想用这种布局构建一个 android 片段:
- 屏幕的上半部分是水平滚动的 RecyclerView。
- 屏幕的下半部分是一个垂直滚动的 RecyclerView。
当底部的 RecyclerView 向底部滚动时,我希望顶部的 RecyclerView 折叠并隐藏(当底部视图滚动到顶部时打开)。
协调器布局似乎是答案,但我遇到的每个示例都在顶部使用 AppBarLayout。包含片段的 activity 已经显示了应用栏;我不想修改它。
如何在 CoordinatorLayout 中实现这两个 RecyclerView 设置而不处理应用栏?
您可以使用 NestedScrollView
、垂直方向的 LinearLayout
作为 NestedScrollView
的子项,并将两个 RecyclerView
添加为 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>