Search code examples
androidandroid-fragmentsandroid-recyclerviewbottom-sheetandroid-motionlayout

RecyclerView in MotionLayout with BottomSheetBehaviour doesn't scroll on touch of RecyclerView


RecyclerView in MotionLayout with BottomSheetBehaviour, While the user drags the BottomSheet on touch of recyclerview, it won't drag up.

It works perfectly when used with ConstraintLayout or when the user touches anywhere other than recyclerview.

As you can see I have used MotionLayout in CoordinatorLayout and the RecyclerView is inside MotionLayout.

Just Replacing it to ConstraintLayout everything works perfectly. Since I am working with MotionLayout not sure how to handle the recyclerview inside MotionLayout.

Code:

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.constraintlayout.motion.widget.MotionLayout
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/rounded_bottom_sheet"
        android:clickable="true"
        android:focusable="true"
        app:layoutDescription="@xml/bottom_sheet_scene"
        app:behavior_hideable="false"
        app:behavior_peekHeight="190dp"
        app:layout_behavior="@string/bottom_sheet_behavior">

        <View
            android:id="@+id/handle"
            android:layout_width="24dp"
            android:layout_height="4dp"
            android:background="@drawable/handle_background" />

        <EditText
            android:id="@+id/drop_search_et"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/_8sdp"
            android:layout_marginTop="@dimen/_24sdp"
            android:layout_marginEnd="@dimen/_12sdp"
            android:background="@drawable/rounded_grey_edit_text"
            android:maxLines="1"
            android:inputType="text"
            android:ellipsize="end"
            android:hint="Where do you want to go?"
            android:paddingStart="@dimen/_10sdp"
            android:paddingTop="@dimen/_6sdp"
            android:paddingEnd="@dimen/_10sdp"
            android:paddingBottom="@dimen/_6sdp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/drop_image"
            app:layout_constraintTop_toTopOf="parent" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/search_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:overScrollMode="never"
            app:layout_constraintTop_toBottomOf="@id/drop_search_et" />

    </androidx.constraintlayout.motion.widget.MotionLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

bottom_sheet_scene.xml

<MotionScene
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content">

    <Transition
        app:constraintSetStart="@id/start"
        app:constraintSetEnd="@id/end"
        app:duration="1000">

    </Transition>


    <ConstraintSet android:id="@+id/start">
        <Constraint
            android:id="@+id/handle"
            android:layout_width="24dp"
            android:layout_height="4dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginTop="@dimen/_8sdp"

        />

     </ConstraintSet>


     <ConstraintSet android:id="@+id/end">
         <Constraint
            android:id="@+id/handle"
            android:layout_width="24dp"
            android:layout_height="4dp"
            android:layout_marginTop="@dimen/_24sdp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"


         />
      </ConstraintSet>
</MotionScene>

Solution

  • I solved it by removing using

    android:nestedScrollingEnabled="false"

    Enabling and disabling the nested scroll for the recyclerview will solve this issue.