I built a very simple example using MotionLayout, but for some reason the onClick does not trigger the animation.
What am I missing??
I have the following layout:
<androidx.constraintlayout.motion.widget.MotionLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layoutDescription="@xml/scene_substitution"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<View
android:id="@+id/animateMe"
android:layout_width="50dp"
android:layout_height="500dp"
android:background="@android:color/holo_red_dark"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<Button
android:id="@+id/startAnimation"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="Click me"
/>
</androidx.constraintlayout.motion.widget.MotionLayout>
And the folloting scene description:
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:motion="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetStart="@+id/start"
motion:constraintSetEnd="@+id/end"
motion:duration="1000">
<OnClick
app:targetId="@+id/startAnimation"
app:clickAction="toggle"
/>
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@+id/animateMe"
android:layout_width="100dp"
android:layout_height="400dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:background="@android:color/holo_blue_bright"
/>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/animateMe"
android:layout_width="300dp"
android:layout_height="100dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:background="@android:color/holo_green_dark"
/>
</ConstraintSet>
</MotionScene>
Finally got it!
I used the wrong namespace value for xmlns:motion
.
It supposed to be xmlns:motion="http://schemas.android.com/apk/res-auto"
, of course...