Search code examples
androidandroid-motionlayout

What is the default state in MotionLayout?


I couldn't find any documentation regarding default state of MotionScene in MotionLayout.

I have simple MotionScene like below

<?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:constraintSetStart="@id/customStart"
        app:constraintSetEnd="@id/customEnd"
        app:duration="250" />


    <ConstraintSet android:id="@+id/customStart">
        <Constraint
            android:id="@id/someId"
            android:layout_width="0dp"
            android:layout_height="0dp" />
    </ConstraintSet>
    <ConstraintSet android:id="@+id/customEnd">
        <Constraint
            android:id="@id/someId"
            android:layout_width="0dp"
            android:layout_height="0dp"/>
    </ConstraintSet>


</MotionScene>

So how does MotionLayout set default state when view is firstly created? And how can I manually set, say customEnd, as default state?


Solution

  • MotionScene now has StateSet element which has an attribute for the default state.

    <StateSet app:defaultState="@id/start"/>