MotionLayout 应用 loadLayoutDescription

p37*_*td8 6 android-motionlayout

我的 MotionLayout 有 2 种不同的行为。这个想法是根据应用程序状态更改它们。但是当我从代码设置时:

if(smth) {
   constraintToolbar.loadLayoutDescription(R.xml.layout_description_1)
} else {
   constraintToolbar.loadLayoutDescription(R.xml.layout_description_2)
}
Run Code Online (Sandbox Code Playgroud)

不应用约束。但它们是在拖动运动后应用的。是否有一些解决方法或者是因为 ConstraintLayout 2.0.0 alpha ?我在用着:

'com.android.support.constraint:constraint-layout:2.0.0-alpha2'
Run Code Online (Sandbox Code Playgroud)

p37*_*td8 2

我在 MotionScene 中有过渡。

<Transition
    motion:constraintSetStart="@id/start"
    motion:constraintSetEnd="@id/end"
    motion:duration="1000"
    motion:interpolator="linear">
Run Code Online (Sandbox Code Playgroud)

在“MotionLayout.loadLayoutDescription”之后未设置初始约束。我补充道:

MotionLayout.setTransition(R.id.start, R.id.end)
Run Code Online (Sandbox Code Playgroud)

并正确应用约束。