How to reset MotionLayout to first ConstraintSet

1.4k views Asked by At

I use a ViewPager have 3 pages. How to reset MotionLayout and re-run animation when a page is re-selected?

Currently, I call method transitionToStart() when a page replaced by another. But if user swipe back too quickly, animation transitionToStart() won't finish.

Is there a better method?

1

There are 1 answers

0
Tobi On

You can do the following:

    motionLayout.setTransition(R.id.transition);
    motionLayout.transitionToEnd();
    if (instant)
        motionLayout.setProgress(1);

You can manually set the progress by calling .setProgress(0) or .setProgress(1)

Based on .setTransition(R.id.transition) you can define start and end constraint (in case you have more than two constraintSets).