【问题标题】:BottomSheet with RecyclerView and other views带有 RecyclerView 和其他视图的 BottomSheet
【发布时间】:2019-11-27 10:30:12
【问题描述】:

我有一个带有 BottomSheet 的 CoordinatorLayout。如果 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>

【问题讨论】:

    标签: android android-recyclerview android-coordinatorlayout bottom-sheet


    【解决方案1】:

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

    【讨论】:

    • 不建议使用 NestedScrollView 作为 RecyclerView 的父级,会妨碍回收项目
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-03
    • 1970-01-01
    相关资源
    最近更新 更多