Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run particular transition in MotionLayout?

I have a MotionScene with 4 ConstraintSets representing 4 states of screen (loading states) and with 3 Transitions between them. When my app state changes from e.g. loading to processing, I want to run Transition 1 (set1 -> set2), when state changes again, I want to run Transition 2 (set2 -> set3). And I can't find a way to do it.

I tried next:

To set current transition with

     motion_layout.setTransition(R.id.set1, R.id.set2)
     motion_layout.transitionToState(R.id.set2)

To just set transition

motion_layout.setTransition(R.id.set1)

To transition to some state:

motion_layout.transitionToState(R.id.set1)

but all of the above methods run all my sets together, even if I use app:autoTransition="none" .


I tried to put everything in one Transition and set app:progress = 0 on , and then control state of animation with progress:

 motion_layout.setProgress(0.25f, 1.0f)

which just runs all animation to the end, or I tried

motion_layout.progress = 0.25f

which don't animate, it just shows me 0.25 progress of animation without any motion.

How to control the flow of animation? How to run particular set? Would it be better to use progress? How to solve it?

P.S. I use

implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta7'
like image 354
StayCool Avatar asked Jun 16 '20 10:06

StayCool


People also ask

How does MotionLayout work?

MotionLayout bridges the gap between layout transitions and complex motion handling, offering a mix of features between the property animation framework, TransitionManager , and CoordinatorLayout . In addition to describing transitions between layouts, MotionLayout lets you animate any layout properties, as well.


1 Answers

Unless you have it should only transition to the state you call if you call ml.transitionToState(R.id.xx);

Remove all autoTransition attributes in you motionScene

like image 78
hoford Avatar answered Oct 08 '22 14:10

hoford