android - 带有 RecyclerView 和其他视图的 BottomSheet
问题描述
我有一个带有 BottomSheet 的 CoordinatorLayout。如果 Bottomsheet 只有一个 RecyclerView,那么一切正常。我试图在 RecyclerView 顶部添加一些 Textview 和按钮,但是当 recyclerview 达到顶部高度时,它会在另一个视图下方滚动。我也希望其他视图也能滚动。如果 BottomSheet 仅包含其他视图(没有 Recyclerview)也可以正常工作。当我结合 RecyclerView 和其他视图元素(按钮、TextView)时,滚动不如预期。
我想将 Recyclerview 上方的视图设置为列表的第一项,但这增加了适配器的复杂性。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:behavior_hideable="false"
app:behavior_peekHeight="80dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text 2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text 3"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:background="@android:color/white"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="true"/>
</LinearLayout>
解决方案
使用 NestedScrollView 作为 LinearLayout 的父级。它会解决你的问题。
推荐阅读
- azure-active-directory - 如何获取 Onedrive (for business) 文件的 UniqueId?
- android - AndroidManifest 添加 admob 后出现 14 个错误
- html - #document 是什么意思?以及如何选择该代码之外的元素?
- typescript - lib.es2015.promise.d.ts(33, 34):未提供“价值”的参数
- javascript - 如何防止div类jquery中的点击动作
- css - Angular Material Theme 不会更改 mat-dialog 强调色
- android - 如何在颤动中更改文本小部件的值
- unit-testing - vuejs 单元测试具有子组件的组件
- entity-framework - Fluent Api 复合主键
- configuration - 是否有任何配置库提供用于合并拆分文件中的修改的本机实现(如 .d 文件夹中所示)