BottomSheet: issue with nested scrolling (RecyclerView & NestedScrollView)

流过昼夜 提交于 2020-01-16 16:48:15

问题


I have a rather complex BottomSheetLayout which layout is as follow

The root view of my bottom sheet is a custom FrameLayout that allows to round it's corner (both background and children). Nothing else (nothing touch-related)

Then, I use the usual ConstraintLayout in order to layout my Bottom sheet.

This ConstraintLayout contains, amongst other views, a vertical RecyclerView:

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="10dp">

    <!-- other views -->

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/events"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginTop="25dp"
        android:layout_marginBottom="74dp"
        app:layout_constraintTop_toBottomOf="@+id/days"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:background="@{viewModel.colors.defaultBackgroundColor}"
        tools:background="#ECF0F3"
        android:orientation="vertical"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        tools:listitem="@layout/event_item"
        tools:itemCount="10" />

</androidx.constraintlayout.widget.ConstraintLayout>

I have no particular issue while dragging my bottom sheet, however, when fully expanded I was expecting the be able to scroll the content of my RecyclerView. But I cannot.

After a lot of researches, I managed to make it scroll by enabling scrolling when my Fragment's view is inflated :

ViewCompat.setNestedScrollingEnabled(this.binding.bottomSheetEvents.getRoot(), true);

However, doing so has a weird consequence. When my bottom sheet's state is EXPANDED, I can finally scroll my RecyclerView, but then there is absolutely no way to drag my Bottom sheet any more : it remains fully expanded.

I have tried a few other ways.

  1. I have tried wrapping my NestedScrollView. In past experience I was able to have the full content of my bottom sheet scrollable thanks to NestedScrollView, but in this case, I only want to scroll my RecyclerView. What ever is above it must remain idle.
  2. I have tired this.binding.bottomSheetEvents.events.setNestedScrollingEnabled(false); but there is no difference.

My belief is that when the bottom sheet is fully expanded, it dispatches scroll events to inner children that can supports its. And, backwards, it knows, at some point, when uses wishes to collapse said bottom sheet. So I guess, something wrong must be happening there.

Further informations:

  • this bottomsheet is included in my fragment which roots view is a CoordinatorLayout obviously.
  • the fragment is also hosted in CoordinatorLayout with an AppBar
  • the include layout uses the app:layout_behavior="@string/bottom_sheet_behavior"
  • and the include layout also uses behavior_fitToContents set to false so that I can use method setExpandedOffset to prevent the bottom sheet to reach the top.
  • Version used : 1.1.0-alpha07

Thanks for the help!

来源:https://stackoverflow.com/questions/56509759/bottomsheet-issue-with-nested-scrolling-recyclerview-nestedscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!