Start motion scene programmatically

后端 未结 5 934
心在旅途
心在旅途 2020-12-30 21:12

I have a motion layout with this layoutDescription: app:layoutDescription=\"@xml/scene\"

scene.xml



        
5条回答
  •  隐瞒了意图╮
    2020-12-30 21:26

    We can simply do like this motion_layout.transitionToEnd()

    But on Activity resumed, It'll start our animation so fast that we may miss the few or the whole animation. so I would suggest to add some delay like.

    GlobalScope.launch (Dispatchers.IO){
            delay(1000)
            withContext(Dispatchers.Main){
                motion_layout.transitionToEnd()
            }
        }
    

    Also you'll need to add Coroutines dependency if not added.

    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'

提交回复
热议问题