【问题标题】:MotionLayout ignores KeyFrameSetMotionLayout 忽略 KeyFrameSet
【发布时间】:2019-07-18 19:39:29
【问题描述】:

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

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

动态场景:

<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 首先从 0 旋转到 90,bottomCard 最后从 -90 旋转到 0

【问题讨论】:

    标签: android xml android-motionlayout


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多