BottomSheetDialogFragment - Allow Scrolling

I have a BottomSheetDialogFragment with a RecyclerView . The problem is that I want to disable the closing function of the BottomSheetDialogFragment tag until the RecyclerView scrolls (currently I cannot scroll my RecyclerView , since trying to always close the BottomSheetDialogFragment ). Any ideas how to achieve this?

+11
source share
4 answers

Just treat it like a BottomSheetDialog and just turn it off drag and drop or touch.

When creating a BottomSheetDialog , it will automatically pack your layout into the Layout Coordinator , so if you want to get a view from your view, call

final behavior BottomSheetBehavior = BottomSheetBehavior.from ((View) view.getParent ());

Then, with this behavior, you can do what you need.

 final BottomSheetBehavior behavior = BottomSheetBehavior.from((View) view.getParent()); behavior.setHideable(false); behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { } @Override public void onSlide(@NonNull View bottomSheet, float slideOffset) { behavior.setState(BottomSheetBehavior.STATE_EXPANDED); } }); 

It worked for me. Hope this helps.

+2
source

The RecyclerView scrolling issue in the BottomSheetDialog can be solved this way.

from: https://android.jlelse.eu/recyclerview-within-nestedscrollview-scrolling-issue-3180b5ad2542

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v4.widget.NestedScrollView android:id="@+id/nestedScrollView" android:layout_width="match_parent" android:layout_height="match_parent" android:overScrollMode="never"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> </android.support.v4.widget.NestedScrollView> </LinearLayout> 
+2
source

Change the behavior in the BottomSheetDialogFragment method in the setupDialog method:

 CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams(); final CoordinatorLayout.Behavior behavior = layoutParams.getBehavior(); if (behavior != null && behavior instanceof BottomSheetBehavior) { ((BottomSheetBehavior) behavior).setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { if (newState == BottomSheetBehavior.STATE_HIDDEN) { dismiss(); } if (newState == BottomSheetBehavior.STATE_DRAGGING) { ((BottomSheetBehavior) behavior).setState(BottomSheetBehavior.STATE_EXPANDED); } } @Override public void onSlide(@NonNull View bottomSheet, float slideOffset) { } }); } 
0
source

Put your RecyclerView in a NestedScrollView , where NestedScroll is the processor parent

-1
source

Source: https://habr.com/ru/post/1260627/


All Articles