带有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>
MotionLayout中具有BottomSheetBehaviour的RecyclerView,当用户在触摸recyclerview时拖动BottomSheet时,它不会向上拖动。当与ConstraintLayout一起使用时,或者当...