Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistent Bottom Sheet in AndroidX

layout_behavior - android.support.design.widget.BottomSheetBehavior is not working

this view is not constrained vertically at runtime it will jump

I am getting this error in Androidx only. So how i can resolve this error.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#efefef"
    tools:context=".MainActivity">


    <include layout="@layout/content_main" />

    <!-- Adding bottom sheet after main content -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:orientation="vertical"
        android:padding="10dp"
        app:behavior_hideable="true"
        app:behavior_peekHeight="56dp"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

        ...... child layouts..


    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

like image 228
Sujeet Kumar Avatar asked Mar 24 '26 19:03

Sujeet Kumar


1 Answers

Since you are using androidx libraries, you have to use the Material Components Library.
Use the class com.google.android.material.bottomsheet.BottomSheetBehavior instead of android.support.design.widget.BottomSheetBehavior:

<LinearLayout     
  app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
..>

or:

   <LinearLayout     
      app:layout_behavior="@string/bottom_sheet_behavior"
    ..>

Also change the ConstraintLayout to CoordinatorLayout.

like image 130
Gabriele Mariotti Avatar answered Mar 26 '26 10:03

Gabriele Mariotti