0

I have BottomSheetDialogFragment with xml like:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            
            <FrameLayout
                android:id="@+id/main_container"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                app:all_constraints/>
            </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.core.widget.NestedScrollView>
</FrameLayout>

Then inflates RecyclerView inside main_container in the onViewCreated:

<androidx.recyclerview.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:orientation="vertical"
    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>

Most cases work normal, but sometimes I can't scroll down RecyclerView, scrolling leads to closing BottomSheet. Tryed:

  • nestedScrollingEnabled = false - for RecyclerView (not scroll at all)
  • requestDisallowInterceptTouchEvent(true) - into custom RecylerView.onTouchEvent (no effect)
Faust
  • 111
  • 1
  • 1
  • 8
  • Try with coordinator layout. Check this answer https://stackoverflow.com/questions/44023420/recyclerview-inside-the-bottomsheet-is-not-working – Gobu CSG Jul 12 '22 at 20:35

1 Answers1

0

This option hides the problem, however it probably doesn't solve it completely:

          recycler.addOnScrollListener(object : RecyclerView.OnScrollListener(){
                    override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
                        if ((recyclerView.layoutManager as? LinearLayoutManager)?.findFirstCompletelyVisibleItemPosition()!=0)
                            disableDragging() //isDraggable = false for BottomSheetBehaviour
                        else
                            enableDragging()
                        super.onScrolled(recyclerView, dx, dy)
                    }
                })
Faust
  • 111
  • 1
  • 1
  • 8