Start Motion Layout automatically (Android Studio)

Viewed 3145

I want to make an animated splashscreen and the Motion Layout should start automatically when you start the app. What can I do to make the Motion Layout start automatically?

3 Answers

Add the line autoTransition="animateToEnd" to your transition

<Transition
    motion:constraintSetStart="@+id/start"
    motion:constraintSetEnd="@+id/end"

    motion:autoTransition="animateToEnd"

    motion:duration="1000">

First, assign an ID to MotionLayout in xml.

then write below codes in your activity:

MotionLayout motionLayout = findViewById(R.id.motion_layout);     
motionLayout.transitionToEnd();

if you want to reverse transition use this line of code:

motionLayout.transitionToStart();

The motion:transitionFlags="disableIntraAutoTransition" will avoid the animations reanimating if the actual state is changed programmatically or by the user.

    <Transition
        motion:constraintSetEnd="@+id/end"
        motion:constraintSetStart="@id/start"
        motion:autoTransition="animateToEnd"
        motion:transitionFlags="disableIntraAutoTransition"
        motion:duration="1200">
    </Transition>
Related