android - 带有 BottomSheetBehaviour 的 MotionLayout 中的 RecyclerView 不会在触摸 RecyclerView 时滚动

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

带有 BottomSheetBehaviour 的 MotionLayout 中的 RecyclerView,当用户在触摸 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>

最佳答案

我通过删除 using 解决了它

android:nestedScrollingEnabled="false"

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

关于android - 带有 BottomSheetBehaviour 的 MotionLayout 中的 RecyclerView 不会在触摸 RecyclerView 时滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59497351/

相关文章:

Android TabLayout 重叠 fragment 的内容

java - 在搜索过程中过滤列表会修改原始数据源

android - 火力地堡用户界面 : How to add new message to the top of recycleView

android - 改变 recyclerview 项目的可见性会改变其他项目的可见性

android - android 7 (N OS) 上的 java.lang.SecurityException : Permission Denial: not allowed to send broadcast android. intent.action.NEW_OUTGOING_CALL

android - Switch 中的重复案例

android - 无法从 onListItemClick 开始 fragment

android - 在嵌套的 FragmentTabHost 中切换选项卡后 fragment 不可见

android - 如何为特定 View 设置动画?

android - torch 应用程序问题