动画时 MotionLayout 未调整大小
MotionLayout not resized when animating
我有这样的看法:
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/expandableModes"
android:layout_width="200dp"
android:layout_height="200dp"
android:paddingBottom="5dp"
app:layoutDescription="@xml/journey_motion"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@id/travelModeText">
....
</androidx.constraintlayout.motion.widget.MotionLayout>
而这个动作布局:
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="@id/endExpand"
app:constraintSetStart="@id/startExpand"
app:duration="1000" />
<ConstraintSet android:id="@+id/startExpand">
<Constraint
android:id="@id/expandableModes"
android:layout_width="200dp"
android:layout_height="200dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@id/travelModeText" />
</ConstraintSet>
<ConstraintSet android:id="@+id/endExpand">
<Constraint
android:id="@id/expandableModes"
android:layout_width="10dp"
android:layout_height="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@id/travelModeText" />
</ConstraintSet>
</MotionScene>
我按代码执行:
binding.expandableModes.transitionToEnd {
print("")
}
我的动画播放了,但我的视图没有调整大小,我错过了什么?
您正在尝试为运动布局本身设置动画。您只能按照此处所述为直接子级设置动画:https://developer.android.com/training/constraint-layout/motionlayout
您需要创建视图的子视图并为其设置动画。
我有这样的看法:
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/expandableModes"
android:layout_width="200dp"
android:layout_height="200dp"
android:paddingBottom="5dp"
app:layoutDescription="@xml/journey_motion"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@id/travelModeText">
....
</androidx.constraintlayout.motion.widget.MotionLayout>
而这个动作布局:
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="@id/endExpand"
app:constraintSetStart="@id/startExpand"
app:duration="1000" />
<ConstraintSet android:id="@+id/startExpand">
<Constraint
android:id="@id/expandableModes"
android:layout_width="200dp"
android:layout_height="200dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@id/travelModeText" />
</ConstraintSet>
<ConstraintSet android:id="@+id/endExpand">
<Constraint
android:id="@id/expandableModes"
android:layout_width="10dp"
android:layout_height="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/guidelineLeft"
app:layout_constraintTop_toBottomOf="@id/travelModeText" />
</ConstraintSet>
</MotionScene>
我按代码执行:
binding.expandableModes.transitionToEnd {
print("")
}
我的动画播放了,但我的视图没有调整大小,我错过了什么?
您正在尝试为运动布局本身设置动画。您只能按照此处所述为直接子级设置动画:https://developer.android.com/training/constraint-layout/motionlayout
您需要创建视图的子视图并为其设置动画。