MsPaladin121
MsPaladin121

Reputation: 73

Is it possible set End State in MotionLayout without animation?

I have items are wrapped in motionLayout and recyclerView in which need set one item to the End state, and leave the rest in the Start state without any animations or blinks, just show. enter image description here

When i try call

transitionToState(endState)

or

transitionToEnd()

the animation happens, but i just need to set the element to End state the first time. And everything should be animated when the user clicks on the items

Upvotes: 5

Views: 1758

Answers (2)

guy.gc
guy.gc

Reputation: 3501

You can seek the transition programmatically: setProgress(1f) will transition without animation to the end state.

Upvotes: 2

Michael Hewett
Michael Hewett

Reputation: 91

You can transition to the end state of your MotionLayout without animation by doing the following:

yourMotionLayout.setTransitionDuration(0)
yourMotionLayout.transitionToEnd()

You can wrap this into an extension function for easier re-use:

/**
 * Triggers the underlying [MotionLayout] to transition to end state immediately.
 */
fun MotionLayout.jumpToEnd() {
    this.setTransitionDuration(0)
    this.transitionToEnd()
}

Upvotes: 7

Related Questions