带有RecyclerView和其他视图的BottomSheet

3
我有一个CoordinatorLayout和一个BottomSheet。如果Bottomsheet只有一个RecyclerView,一切都很正常。但是,我尝试在RecyclerView的顶部添加一些TextView和按钮,但当RecyclerView达到顶部高度时,它会滚动到其他视图下面。我希望其他视图也能滚动。 如果BottomSheet只包含其他视图(没有RecyclerView),也可以正常工作。 当我将RecyclerView和其他视图元素(Button, 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>
1个回答

6

使用NestedScrollView作为LinearLayout的父容器,这将解决你的问题。


不建议将NestedScrollView作为RecyclerView的父级,这会阻止回收项目。 - Momen Zaqout

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接