Reputation: 67
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?
Upvotes: 2
Views: 1619
Reputation: 898
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).
Upvotes: 1