Java – BottomSheet scrolling problem – Android

BottomSheet scrolling problem – Android… here is a solution to the problem.

BottomSheet scrolling problem – Android

I need BottomSheet to stop in two locations. I have the following BottomSheet code.

<android.support.design.widget.CoordinatorLayout 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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        ....
    </RelativeLayout>

<FrameLayout
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
           <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

<LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                    android:minHeight="1000dp"
                    android:orientation="vertical">
                    ....
                </LinearLayout>
          </ScrollView>
     </FrameLayout>
</android.support.design.widget.CoordinatorLayout>

and

View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);
final BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
    @Override
    public void onStateChanged(@NonNull View bottomSheet, int newState) {
         React to state change
        Log.e("onStateChanged", "onStateChanged:" + newState);
        if (newState == BottomSheetBehavior.STATE_EXPANDED) {
            behavior.setPeekHeight(600);
            showAgain.setVisibility(View.GONE);
            mMap.getUiSettings().setScrollGesturesEnabled(false);
        } else if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
            if (behavior.getPeekHeight() == 600) {
                behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                behavior.setPeekHeight(80);
                mMap.getUiSettings().setScrollGesturesEnabled(false);
            } else if (behavior.getPeekHeight() == 80) {
                showAgain.setVisibility(View.VISIBLE);
                mMap.getUiSettings().setScrollGesturesEnabled(true);
            }
        }
    }
    
@Override
    public void onSlide(@NonNull View bottomSheet, float slideOffset) {
         React to dragging events
        Log.e("onSlide", "onSlide " + slideOffset);
    }
});
    
behavior.setPeekHeight(600);

Except for one thing, this code works fine. The first time I have to scroll up the BottomSheet, then I can scroll it down. I can’t scroll down the sheet directly.

We would appreciate it.

Solution

I

don’t know if this will solve your problem, but I did this by replacing BottomSheet with NestedScrollView in BottomSheet.

Related Problems and Solutions