2

I've been watching motion animation layout videos and I've seen that the animation gets activated after a click or a swipe, how can I make the animation start when all the views have been created, like for example in a Hero Animation?

Andrey Solera
  • 2,311
  • 2
  • 26
  • 51
  • I have't tried it personally if it's working after a click how about calling performClick() on a view after allviews created? – AgentP Jun 06 '20 at 17:58

1 Answers1

1

You could use methods transitionToStart / transitionToEnd on MotionLayout to perform animations from code. And therefore you can call this methods in onStart/onResume Fragment or Activity methods for example. https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionLayout#transitionToEnd()

Example:

class MyFragment: Fragment() {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        // Start animation programmatically after all views created
        motion_layout.transitionToEnd()
    }
}
ZSergei
  • 807
  • 10
  • 18