BottomSheetBehavior - only allow dragging on part of view

Viewed 345

I have a bottom sheet implemented using BottomSheetBehavior within a CoordinatorLayout. My BottomSheet has a top appbar sort of title bar, and then some scrollable content. Something like this.

enter image description here


<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    ...

    <LinearLayout
        android:id="@+id/bottom_sheet"
        app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:focusable="true"
        android:orientation="vertical">

        ...

    </LinearLayout>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

I want the user to be able to drag the bottom sheet to the expanded, half-expanded, and hidden positions, but only when dragging the bottom sheet's top appbar. So if the bottom sheet is at the half-expanded state, dragging/scrolling/flinging the scrollable content within the bottom sheet should not adjust it's position - it should remain half-expanded. But dragging the top appbar up/down should cause the bottom sheet to perform its normal draggable behavior.

Is this possible with BottomSheetBehavior?

0 Answers
Related