How to start Animation immediately after onCreate?

前端 未结 7 1634
借酒劲吻你
借酒劲吻你 2020-12-15 06:58

I am following http://developer.android.com/guide/topics/graphics/view-animation.html#frame-animation with minor changes. I have decided to make the animation loop and want

7条回答
  •  天命终不由人
    2020-12-15 07:35

    As this question was asked some long time ago, I have encounter same problem in 2019 with usage of transitions-Everywhere or AndroidX Transitions. And the only solution for me was to use @Muzikant answer. Simply call in your onCreate()

    rootViewOfYourLayout.post {
                TransitionManager.beginDelayedTransition(rootViewOfYourLayout)
                someViewId.visibility = View.VISIBLE
            }
    

    And it works perfectly, for example in my case for Splash screen.

    Update
    As after some testing, it appears this solution has minor issue. Animation is started and you block the phone or move app to background, and in result when app again in foreground it's just frozen as no TransitionListener callbacks received, so in my case onTransitionEnd() wasn't called where was located logic to navigate user to next screen.

    For now this works for me without problems :

      override fun onWindowFocusChanged(hasFocus: Boolean) {
       if(hasFocus && isAnimationStarted.not()){
       rootViewOfYourLayout.post {
              TransitionManager.beginDelayedTransition(rootViewOfYourLayout)
              someViewId.visibility = View.VISIBLE
                }
      }
    }
    

提交回复
热议问题