Main.xml file
<?xml version="1.0" encoding="utf-8"?> <layout> <androidx.coordinatorlayout.widget.CoordinatorLayout android:id="@+id/container" android:layout_marginBottom="0dp" android:fitsSystemWindows="true" android:orientation="vertical" 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" tools:context=".MainActivity"> <androidx.appcompat.widget.LinearLayoutCompat android:layout_width="match_parent" android:layout_height="match_parent" android:background="#80FFFFFF" android:layout_marginBottom="280dp"> <androidx.appcompat.widget.AppCompatImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitXY" app:srcCompat="@drawable/img_demo" /> </androidx.appcompat.widget.LinearLayoutCompat> <LinearLayout android:id="@+id/bottom_sheet" android:layout_width="match_parent" android:layout_height="match_parent" android:focusable="false" android:focusableInTouchMode="true" android:orientation="vertical" android:background="#E1E0E0" app:behavior_hideable="false" app:behavior_peekHeight="320dp" app:layout_behavior="@string/bottom_sheet_behavior"> <View android:id="@+id/dash" android:layout_width="50dp" android:layout_height="6dp" android:layout_marginTop="5dp" android:layout_gravity="center|top" android:background="@drawable/line_shape" /> <androidx.appcompat.widget.AppCompatTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="25sp" android:gravity="center" android:text="Hello world"> </androidx.appcompat.widget.AppCompatTextView> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY" android:src="@drawable/demo_2" /> </LinearLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout> </layout>
Main. java file
import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.databinding.DataBindingUtil; import android.os.Bundle; import android.view.View; import android.widget.LinearLayout; import com.bottomsheetbehavior.databinding.ActivityMainBinding; import com.google.android.material.bottomsheet.BottomSheetBehavior; public class MainActivity extends AppCompatActivity { ActivityMainBinding binding; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding = DataBindingUtil.setContentView(this,R.layout.activity_main); BottomSheetBehavior<LinearLayout> view = BottomSheetBehavior.from(binding.bottomSheet); view.setDraggable(true); view.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { if (newState == BottomSheetBehavior.STATE_COLLAPSED) { // binding.scrollView.isEnableScrolling = false }else if (newState == BottomSheetBehavior.STATE_EXPANDED) { // binding.scrollView.isEnableScrolling = true } } @Override public void onSlide(@NonNull View bottomSheet, float slideOffset) { } }); } }