8

I need the BottomSheet to stop at two positions. I have the following code for BottomSheet.

<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); 

This code works fine except one thing. The very first time I have to scroll up the BottomSheet and then I can down scroll it. I cannot directly down scroll the sheet.

Any help will be appreciated.

3 Answers 3

33

I don't know if this will be a solution to your problem, but I fixed quite a bit of scroll issues in a BottomSheet by replacing the ScrollView in the BottomSheet with a NestedScrollView.

Sign up to request clarification or add additional context in comments.

1 Comment

Absolutely right! NestedScrollView without any specific flags, resolves such issues even with BottomSheetDialogFragment. I experienced the same!
7

Hope here you will find a solution

https://www.androidhive.info/2017/12/android-working-with-bottom-sheet/

and change ScrollView with NestedScrollView

p.s. Actually there's too mush code there

1 Comment

A link to a solution is welcome, but please ensure your answer is useful without it: add context around the link so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. Answers that are little more than a link may be deleted.
1

This is what worked for me,

  • Set a Nested Scrollview as the parent

  • Make recycler view height wrap_content

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.