1

我正在尝试为动画的第一部分旋转一个 topCard,并为第二个部分旋转一个 bottomCard。要持有bottomCard,直到我使用KeyFragmentSet。当我单击 topCard 时,MotionLayout 会忽略 KeyFragmentSet 并在整个动画时间内同时旋转两张卡片。

尝试用 setOnClickListener 替换 XML onClick,但同样的事情发生了。

运动场景:

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

    <Transition android:id="@+id/flip_transition"
        app:constraintSetEnd="@+id/bottom"
        app:constraintSetStart="@+id/top"
        app:duration="1500">

        <OnClick app:targetId="@id/CL_top_card"
            app:clickAction="transitionToEnd"/>

        <KeyFrameSet android:id="@+id/flip_keyFrameSet">
            <KeyAttribute
                app:targetId="@+id/CL_top_card"
                app:framePosition="50"
                android:rotationY="90"/>

            <KeyAttribute
                app:targetId="@+id/CL_bottom_card"
                app:framePosition="50"
                android:rotationY="-90"/>
        </KeyFrameSet>

    </Transition>

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

        <Constraint
            android:id="@id/CL_top_card"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="40dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:rotationY="0"/>

        <Constraint
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="40dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:id="@id/CL_bottom_card"
            android:rotationY="-90"/>
    </ConstraintSet>

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

        <Constraint
            android:id="@id/CL_top_card"
            android:rotationY="90"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="40dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

        <Constraint
            android:id="@id/CL_bottom_card"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="40dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:rotationY="0"/>
    </ConstraintSet>

</MotionScene>

xml布局:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<android.support.constraint.motion.MotionLayout
    android:id="@+id/ML_trust_card"
    android:layout_width="match_parent"
    android:layout_height="350dp"
    app:layoutDescription="@xml/scene_flip">


    <android.support.constraint.ConstraintLayout
        android:id="@+id/CL_top_card"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:rotationY="0">

        <TextView
            android:id="@+id/tx_task_question"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="40dp"
            android:gravity="center"
            android:text="TOPtopTOPtopTop00000000000000000000000"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </android.support.constraint.ConstraintLayout>

    <android.support.constraint.ConstraintLayout
        android:id="@+id/CL_bottom_card"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:rotationY="-90">

        <TextView
            android:id="@+id/tx_task_answer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="40dp"
            android:gravity="center"
            android:text="bottombottombottombottom"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>
    </android.support.constraint.ConstraintLayout>

</android.support.constraint.motion.MotionLayout>

我用:

实施 'com.android.support.constraint:constraint-layout:2.0.0-beta2'

我希望 topCard rotateY 首先从 0 到 90,bottomCard rotateY 最后从 -90 到 0

4

1 回答 1

0

好的。只需在 KeyAttributes 中将 app:targetId 替换为 app:motionTarget。

于 2019-07-18T23:30:17.117 回答