gpt4 book ai didi

android - MotionLayout - OnSwipe 不适用于 ViewPager2/RecyclerView

转载 作者:行者123 更新时间:2023-12-04 13:38:20 24 4
gpt4 key购买 nike

onSwipe 手势不适用于 ViewPager2/RecyclerView,但是如果我用 ImageView 替换 ViewPager2/RecyclerView,它会开始正常工作。

activity_main.xml

<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/motionLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/motion_scene">

<androidx.constraintlayout.widget.Guideline
android:id="@+id/glTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.7" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/glBottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="1.7" />

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager"
android:layout_width="0dp"
android:layout_height="0dp"
android:src="@drawable/red"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

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

motion_scene.xml
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">

<Transition
motion:constraintSetEnd="@+id/end"
motion:constraintSetStart="@+id/start"
motion:duration="300"
motion:motionInterpolator="easeOut">

<OnSwipe
motion:dragDirection="dragDown"
motion:touchAnchorId="@+id/viewpager"
motion:touchAnchorSide="bottom" />

</Transition>

<ConstraintSet android:id="@+id/start">


</ConstraintSet>


<ConstraintSet
android:id="@+id/end"
motion:deriveConstraintsFrom="@id/start">

<Constraint
android:id="@id/ivPoster"
motion:layout_constraintBottom_toBottomOf="@+id/glBottom"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toBottomOf="@+id/glTop" />

</ConstraintSet>

</MotionScene>

最佳答案

包括你ViewPager进入 NestedScrollView并在 NestedScrollView 上进行 OnSwipe 事件而不是 ViewPager

关于android - MotionLayout - OnSwipe 不适用于 ViewPager2/RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60493973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com