Android 使用运动布局翻转和随机播放动画

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

我想创建像这样的动画。我能够实现卡片翻转动画并且它如预期的那样流畅,但是我无法让这个洗牌动画工作,就像卡片翻转后它们被收集在一个点然后再次分发。尽管进行了多次尝试,但我无法获得流畅的动画。我的动画路径变成了这样。

这是我的运动场景文件。

<?xml version="1.0" encoding="utf-8"?>
<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="5000"
        >
        <OnSwipe
            motion:dragDirection="dragRight"
            motion:touchAnchorId="@+id/button"
            motion:touchAnchorSide="right" />

        <KeyFrameSet>

            <KeyPosition
                motion:framePosition="50"
                motion:keyPositionType="parentRelative"
                motion:motionTarget="@+id/button"
                motion:percentY="1" />

            <KeyPosition
                motion:framePosition="70"
                motion:keyPositionType="parentRelative"
                motion:motionTarget="@+id/button"
                motion:pathMotionArc="flip"
                motion:curveFit="spline"
                motion:percentX="-0.1"
                motion:percentY="0.8" />

            <KeyPosition
                motion:framePosition="80"
                motion:keyPositionType="parentRelative"
                motion:motionTarget="@+id/button"
                motion:percentX="0.7"
                motion:percentY="0.7" />


        </KeyFrameSet>
    </Transition>

    <ConstraintSet android:id="@+id/start">
        <Constraint
            android:id="@+id/button"
            android:layout_width="64dp"
            android:layout_height="64dp"
            android:layout_marginStart="8dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent">
            <CustomAttribute
                motion:attributeName="backgroundColor"
                motion:customColorValue="#D81B60" />
        </Constraint>
    </ConstraintSet>

    <ConstraintSet android:id="@+id/end">
        <Constraint
            android:id="@+id/button"
            android:layout_width="64dp"
            android:layout_height="64dp"
            android:layout_marginEnd="8dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintTop_toTopOf="parent">
            <CustomAttribute
                motion:attributeName="backgroundColor"
                motion:customColorValue="#9999FF" />
        </Constraint>
    </ConstraintSet>

</MotionScene>
android android-animation android-motionlayout
© www.soinside.com 2019 - 2024. All rights reserved.