首页 > 解决方案 > Android - Motion Layout 过度拉伸效果

问题描述

我想在约束布局 2.1 中滑动时实现拉伸功能。我有我想在向下滑动视图时扩展的motionlayout。如果我使用新的 Spring 属性,只有当我让过渡自动完成时,我才会获得很好的超调效果,但是如果我完全通过滑动完成动画,它会停止而没有任何弹簧效果。我想要有过度拉伸效果,当我释放它时,应该有一些基于弹簧值的弹簧动画。可能吗?

这是我当前的代码

<androidx.constraintlayout.motion.widget.MotionLayout
        android:id="@+id/motionLayout"
        app:layoutDescription="@xml/scene_02"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        android:focusableInTouchMode="false"
        android:background="@color/black_semi"
        app:layout_constraintStart_toStartOf="parent">

        <View
            android:id="@+id/area"
            android:layout_width="1dp"
            android:layout_height="1dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
             />
        <View
            android:id="@+id/button"
            android:background="@color/error_red"
            android:layout_width="164dp"
            android:layout_height="34dp"
            android:layout_marginBottom="10dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            />

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

运动文件

<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="1000">
        <OnSwipe
            motion:springStiffness="80"
            motion:springDamping="5"
            motion:autoCompleteMode="spring"
            motion:dragDirection="dragDown"
            motion:touchAnchorId="@id/button"
            motion:touchRegionId="@id/button"
            motion:touchAnchorSide="bottom" />
    </Transition>

    <ConstraintSet android:id="@+id/start">
        <Constraint android:id="@id/button">
            <Layout
                android:layout_width="164dp"
                android:layout_height="34dp"
                motion:layout_constraintTop_toTopOf="parent"
                motion:layout_constraintStart_toStartOf="parent"
                motion:layout_constraintEnd_toEndOf="parent"
                android:layout_marginTop="20dp" />
        </Constraint>
    </ConstraintSet>

    <ConstraintSet
        android:id="@+id/end"
        motion:deriveConstraintsFrom="@id/start">
        <Constraint android:id="@id/button"
            motion:quantizeMotionInterpolator="overshoot">
            <Layout
                android:layout_width="164dp"
                android:layout_height="34dp"
                motion:layout_constraintTop_toTopOf="parent"
                motion:layout_constraintStart_toStartOf="parent"
                motion:layout_constraintEnd_toEndOf="parent"
                android:layout_marginTop="200dp" />
        </Constraint>
    </ConstraintSet>

</MotionScene>

标签: androidandroid-constraintlayoutandroid-motionlayout

解决方案


伙计,把运动布局抛在脑后,你需要动画吗?尝试使用撰写


推荐阅读