Search code examples
androidandroid-studiotabletbottom-sheetandroid-bottomsheetdialog

Why does Bottom Sheet Dialog not expand on tablet?


I have impelemented a BottomSheetDialog in my app but when I install it on a tablet and have the tablet laying down it does not expand fully on first click. It expands up to Collapsed state first and you have to drag it up to see everything. Why does it do this? Is it some setting you can change in your style?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
    app:behavior_peekHeight="0dp"
    >
   ...

</LinearLayout>
val view = layoutInflater.inflate(R.layout.home_bottom_sheet_dialog, null)
val bottomSheetDialog = BottomSheetDialog(activity!!)

bottomSheetDialog.setContentView(view)
bottomSheetDialog.show()

I use API 22 AndroidX with kotlin.

enter image description here enter image description here


Solution

  • As Sinan Ceylan said this part of the layout is not needed.

    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" app:behavior_peekHeight="0dp"

    But to fix my problem I sat the peakHeight variable of BottomSheetBehavior to something large before it is shown.

    bottomSheetDialog.setContentView(view)
    bottomSheetDialog.behavior.peekHeight = 1000
    bottomSheetDialog.show()