Is it possible set End State in MotionLayout without animation?

Viewed 1014

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

2 Answers

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()
}

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

Related