Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding BottomSheet Behavior Collapsed vs Hidden

I have a bottom sheet with its height and width set to match_parent. So when on button click I set the behavior to STATE_EXPANDED like this:

mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

My Bottomsheet is defined as below:

    <FrameLayout
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:elevation="@dimen/design_appbar_elevation"
        app:behavior_hideable="true"
        app:layout_behavior="@string/bottom_sheet_behavior">

        <include
            android:id="@+id/bottom_sheet_content"
            layout="@layout/bottomsheet_layout" />

    </FrameLayout>

I am monitoring states with the BottomSheet Callbacks.

  • I click on a button and bottom sheet expanded to full screen.
  • Its current State is STATE_EXPANDED
  • I quickly swipe down on the bottom sheet. (Not fully drag till it closed, simple swipe down like scrolling)
  • It stops at the middle and its state is logged as STATE_COLLAPSED
  • If I swipe again it is all gone and its state is STATE_HIDDEN

I don't understand why it stops in the middle. How can I make it hidden with a single swipe.

I tried that by setting peek_height to 0dp. By this, it never encounters the STATE_HIDDEN. When hidden, its state becomes STATE_COLLAPSED. I just don't understand this states.

How to achieve STATE_HIDDEN with a single swipe down?

like image 436
kirtan403 Avatar asked Sep 14 '16 07:09

kirtan403


People also ask

What is bottom sheet behavior?

Android Bottom Sheet is a component that slides up from the bottom of the screen having multiple options. Here are the examples of the Bottom sheet from apps. There are two types of bottom sheets, Persistent Bottom Sheet and Modal Bottom Sheet.

How can I dim the background when BottomSheet is displayed without using dialog?

Using the Interface - onSlide which as a parameter slideOffSet of type float , can be used to dim the background.

How do I disable BottomSheetDialogFragment dragging?

Disable drag of BottomSheetDialogFragment Even if we have made the BottomSheetDialogFragment as expanded, user can hold the top part of the BottomSheet and drag to show peek view. It can also be disabled by overriding onStateChanged() . This will set the expanded state even if user drags the view.

When to use bottom sheet in android?

Standard bottom sheets display content that complements the screen's primary content. They remain visible while users interact with the primary content. Modal bottom sheets are an alternative to inline menus or simple dialogs on mobile and provide room for additional items, longer descriptions, and iconography.


1 Answers

Kinda late but I just stumbled upon this while searching for something similar.

This is how you can skip the collapsed state:

In XML by adding app:behavior_skipCollapsed="true" to the BottomSheet view.

OR

Programmatically with setSkipCollapsed(boolean).

like image 71
Andre Romano Avatar answered Oct 28 '22 23:10

Andre Romano