我努力创建更多通用的运动布局场景。到目前为止,我看过的每个教程示例都考虑使用app:constraintSetStart="@+id/constraintSet1"
app:constraintSetEnd="@+id/constraintSet2"
这是我的运动场景xml,也许某些属性被错误地声明。
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition android:id="@+id/title1_motion"
app:duration="1000"
app:constraintSetEnd="@+id/title1_down">
<onClick
app:clickaction="toggle"
app:targetId="@id/title1_down" />
</Transition>
<ConstraintSet android:id="@+id/title1_down">
<Constraint android:id="@+id/textView1">
<Layout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintEnd_toStartOf="@+id/textView2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
<Transform android:translationY="50dp" />
</Constraint>
</ConstraintSet>
</MotionScene>
我现在实现的是一个简化的机制,该机制跟踪当前的constraintSetId
和MotionLayout.TransitionListener
。根据上一次的运动布局转换,可以使用
transitionToState(int id)
后跟transitionToEnd()
,其ID来自转换监听器。
实现了从任何constraintSet过渡的效果。以编程方式执行此操作是唯一可行的方法吗?