首页 > 解决方案 > 带有 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>

标签: androidandroid-recyclerviewandroid-coordinatorlayoutbottom-sheet

解决方案


使用 NestedScrollView 作为 LinearLayout 的父级。它会解决你的问题。


推荐阅读