I'm playing around with the MotionLayout in Android. I'm using the alpha 2 version.
'com.android.support.constraint:constraint-layout:2.0.0-alpha2'
I want to react to two different button clicks and trigger an animation for each of them. My current approach is to set two Transitions
in the MotionScene
with an OnClick
trigger in each one.
The problem is that only the first transition seems to be found. For the second one just nothing happens. Am I doing something wrong or can you just set one transition per MotionScene
? If that's the case ist there a different solution to the problem?
Here are the important parts of my Motion Scene
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetStart="@id/startHome"
motion:constraintSetEnd="@id/endHome"
motion:duration="300">
<OnClick
motion:mode="toggle"
motion:target="@+id/imageView_bottom_home" />
</Transition>
<Transition
motion:constraintSetStart="@id/startSearch"
motion:constraintSetEnd="@id/endSearch"
motion:duration="300">
<OnClick
motion:mode="toggle"
motion:target="@+id/imageView_bottom_search" />
</Transition>
<ConstraintSet android:id="@+id/startSearch">
<Constraint
android:id="@id/imageView_bottom_search"
...startConstraints... />
</ConstraintSet>
<ConstraintSet android:id="@+id/endSearch">
<Constraint
android:id="@id/imageView_bottom_search"
...endConstraints... />
</ConstraintSet>
<ConstraintSet android:id="@+id/startHome">
<Constraint
android:id="@id/imageView_bottom_home"
...startConstraints... />
</ConstraintSet>
<ConstraintSet android:id="@+id/endHome">
<Constraint
android:id="@id/imageView_bottom_home"
...endConstraints... />
</ConstraintSet>
Any help appreciated.
Best regards
I had the same problem. The solution I found was to select which one transitions:
(in java code)...
MotionLayout motionConteiner = findViewById(R.id.motion_container);
button1.setOnClickListener((v) -> {
motionConteiner.setTransition(R.id.start1, R.id.end1);
motionConteiner.transitionToEnd();//
});
button2.setOnClickListener((v) -> {
motionConteiner.setTransition(R.id.start2, R.id.end2);
motionConteiner.transitionToEnd();//
});