1

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!

Mackovich
  • 3,319
  • 6
  • 35
  • 73
  • Are you trying to disable the dragging behaviour of the bottom sheet? – Rodrigo Queiroz Jun 08 '19 at 21:25
  • The thing that might be happening is that you recyclerview has no other element to show up when the bottomsheet is fully opened try to add more items to the recyclerview. – Sayok Majumder Jun 08 '19 at 21:40
  • @rodrigo-queiroz I am not. All I wish is to have the same behavior as though my bottom sheet root view is that of a NestedScrollView, meaning content starts scrolling vertically upwards when the bottom sheet is fully expanded. Then, If I scroll the opposite way (downwards), the sheet starts collapsing if its content reached the top. That is not the case right now unless I disable nested scrolling on the root view of my bottom sheet. But then, this somehow makes it impossible to collapse the sheet. It remains expanded at all time unless I add a control to manually set the collapse state. – Mackovich Jun 08 '19 at 22:18
  • @sayok-majumder ah, if somehow that could be the case. Unfortunately, it isn't. Using the same data set, I can clearly scroll when enabling nested scrolling on my bottom sheet's root view. So no, the RecyclerView won't scroll, and I honestly don't exactly know why. – Mackovich Jun 08 '19 at 22:21
  • @RodrigoQueiroz I have a recyclerview inside bottomsheetdialogfragment and i want to disable the dragging down behavior of the bottomsheet. How to do that? – Aman Verma Dec 30 '19 at 12:32
  • 1
    @Sniper I suggest you take a look here, [disabling user dragging on bottomsheet](https://stackoverflow.com/questions/35794264/disabling-user-dragging-on-bottomsheet/50133382#50133382). – Rodrigo Queiroz Dec 30 '19 at 20:56

0 Answers0