【问题标题】:RecyclerView in MotionLayout with BottomSheetBehaviour doesn't scroll on touch of RecyclerView带有 BottomSheetBehaviour 的 MotionLayout 中的 RecyclerView 在触摸 RecyclerView 时不会滚动
【发布时间】:2019-12-27 07:18:04
【问题描述】:

MotionLayout 中的RecyclerView 与BottomSheetBehaviour,当用户在触摸recyclerview 时拖动BottomSheet,它不会向上拖动。

当与 ConstraintLayout 一起使用或当用户触摸除 recyclerview 之外的任何地方时,它可以完美地工作。

如您所见,我在 CoordinatorLayout 中使用了 MotionLayout,而 RecyclerView 在 MotionLayout 中。

只需将其替换为 ConstraintLayout 一切正常。由于我正在使用 MotionLayout,因此不知道如何处理 MotionLayout 中的 recyclerview。

代码:

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

【问题讨论】:

    标签: android android-fragments android-recyclerview bottom-sheet android-motionlayout


    【解决方案1】:

    我通过删除解决了它使用

    android:nestedScrollingEnabled="false"

    启用和禁用recyclerview的嵌套滚动将解决这个问题。

    【讨论】:

      猜你喜欢
      • 2020-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多