【问题标题】:MotionLayout - OnSwipe not working with ViewPager2/RecyclerViewMotionLayout - OnSwipe 不适用于 ViewPager2/RecyclerView
【发布时间】:2020-06-15 01:14:30
【问题描述】:

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

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>

【问题讨论】:

    标签: android android-animation android-constraintlayout android-motionlayout


    【解决方案1】:

    ViewPager 包含在NestedScrollView 中,并在NestedScrollView 而不是ViewPager 上进行 OnSwipe 事件

    【讨论】:

      【解决方案2】:

      今天遇到同样的问题,通过搜索发现已经在RecyclerView Version 1.1.0-beta04禁用了

      当 RecyclerView 无法在该方向滚动时,分派给嵌套预滚动的 dx 和 dy 参数将归零 (aosp/1105373)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-09-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-07
        相关资源
        最近更新 更多