Saikrishna Rajaraman
Saikrishna Rajaraman

Reputation: 3273

MotionLayout jump to end ConstraintSet programmatically

There is an option to jump to end ConstraintSet in XML in MotionLayout.

<Transition
    app:autoTransition="jumpToEnd"
    motion:constraintSetEnd="@+id/constraintStart"
    motion:constraintSetStart="@+id/constraintEnd"
    motion:duration="300" />

Can this be done programmatically?

Upvotes: 1

Views: 1871

Answers (3)

aLLLiyyy
aLLLiyyy

Reputation: 19

Use the setProgress to 1f method did take effect ,but I can not receive the onTransitionCompleted event in TransitionListener

Upvotes: 0

MJ Studio
MJ Studio

Reputation: 4611

use transitionToEnd() method of MotionLayout

Upvotes: 0

Saikrishna Rajaraman
Saikrishna Rajaraman

Reputation: 3273

I figured it out. In order to jump to a ConstraintSet set the progress of MotionLayout to 1.

motionLayout?.setProgress(1.0f)

When you have multiple transitions, then set the state of MotionLayout to final ConstraintSet and then set the progress to 1.

motionLayout?.setState(R.id.endConstraintSet,ConstraintSet.MATCH_CONSTRAINT,ConstraintSet.MATCH_CONSTRAINT)
motionLayout?.setProgress(1.0f)

Upvotes: 1

Related Questions