I created two basically consistent animations based on MotionLayout, one sliding up and the other sliding down. I started the two animations at the same time, but occasionally they are out of sync, it is more like the animation is executed serially. Is there any API to synchronize them?
like this occasionally abnormal
<?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">
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@+id/guide_line"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_end="0dp" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/guide_line"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="0dp" />
</ConstraintSet>
<Transition
app:constraintSetEnd="@id/end"
app:constraintSetStart="@+id/start"
app:duration="300"
app:motionInterpolator="linear" />
</MotionScene>
viewBinding.playerBottomLl.setTransitionListener(object : MotionLayout.TransitionListener{
override fun onTransitionStarted(p0: MotionLayout?, p1: Int, p2: Int) {
LogUtils.e("TestMotion", "bottom: start: ${System.currentTimeMillis()}")
}
override fun onTransitionChange(p0: MotionLayout?, p1: Int, p2: Int, p3: Float) {
}
override fun onTransitionCompleted(p0: MotionLayout?, p1: Int) {
LogUtils.e("TestMotion", "bottom: complete: ${System.currentTimeMillis()}")
}
override fun onTransitionTrigger(p0: MotionLayout?, p1: Int, p2: Boolean, p3: Float) {
}
})
}
***
override fun onVisibilityChanged(isVisible: Boolean) {
LogUtils.e("TestMotion", "bottom: onVisibilityChanged: ${System.currentTimeMillis()}")
if (isVisible) {
viewBinding.playerBottomLl.transitionToEnd()
} else {
viewBinding.playerBottomLl.transitionToStart()
}
}
MotionLayout instances are independent. If you want strict synchronization of two drive the setProgress methods yourself. You can do that in several ways: