我试图在动画的第一部分旋转Y的topCard,在第二部分旋转Y的bottomCard。为了保留bottomCard直到我使用KeyFragmentSet。当我单击topCard时,MotionLayout会忽略KeyFragmentSet并在整个动画时间内同时同时旋转两个卡。
尝试用setOnClickListener替换XML onClick,但是会发生同样的事情。
MotionScene:
<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旋转Y,bottomCard最后从-90到0旋转Y。
答案 0 :(得分:0)
好的。只需将KeyAttributes中的app:targetId替换为app:motionTarget。