AnimationDrawable not playing

前端 未结 6 784
独厮守ぢ
独厮守ぢ 2020-12-31 00:22

So I want my animation to start as soon as the activity is created, but for some reason no matter what I try will get it to start. I can get it to start by having a click ev

6条回答
  •  感动是毒
    2020-12-31 00:36

    I know this is an old question, but I was having the same problem, but the answers weren't helping me. After spending hours working on it I finally found out that my problem was that I had added android:src="@drawable/myanimation" to the imageview container. Once I removed this the above answers worked. I think the animation was running but by setting the src the first image of the animation was on top of it, and thus I thought it wasn't playing.

    • My final code has an XML file with the animation saved in the drawable folder
    • My layout has an imageview with no android:src defined and is set to invisible
    • In onCreate I set the imageview to visible and setBackgroundResource to my animation described in the XML file
    • in onWindowFocusChanged I start the animation.

提交回复
热议问题