为什么使用NestedScrollView无法自动完成MotionLayout折叠动画?

问题描述 投票:0回答:1

我已经使用MotionLayout而不是Coordinator创建了自定义的折叠视图,除了自动完成动画外,其他所有功能都可以正常工作,或者在协调器中我们可以称其为捕捉,例如当我们在之间滚动和停止滚动时,折叠视图将自动捕捉顶部或底部。但是如果我在NestedScrollView中使用MotionLayout,则不会发生这种情况。我已经创建了示例来演示这一点。我还添加了app:onTouchUp="autoComplete",但它不起作用。

motion_layout.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:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/motion_scene">

<View
    android:id="@+id/collapsible"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/red" />

<androidx.core.widget.NestedScrollView
    android:id="@+id/nested_scroll_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <View
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:background="#EEE" />

    ///.......///

    </LinearLayout>

</androidx.core.widget.NestedScrollView>

motion_scene.xml

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

    <Transition
        app:constraintSetEnd="@id/end"
        app:constraintSetStart="@id/start"
        app:duration="1000">

        <OnSwipe
            app:dragDirection="dragUp"
            app:onTouchUp="autoComplete"
            app:touchAnchorId="@id/nested_scroll_view"
            app:touchAnchorSide="top" />

    </Transition>

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

        <Constraint
            android:id="@+id/collapsible"
            android:layout_width="0dp"
            android:layout_height="300dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Constraint
            android:id="@id/nested_scroll_view"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/collapsible" />

    </ConstraintSet>

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

        <Constraint
            android:id="@+id/collapsible"
            android:layout_width="0dp"
            android:layout_height="100dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Constraint
            android:id="@id/nested_scroll_view"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/collapsible" />

    </ConstraintSet>

</MotionScene>
android android-constraintlayout android-coordinatorlayout android-nestedscrollview android-motionlayout
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.