AnimationDrawable not playing

前端 未结 6 771
独厮守ぢ
独厮守ぢ 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条回答
  •  Happy的楠姐
    2020-12-31 00:52

    I think you have to start the animation after initialization of the view in question is complete. You should be able to do something like:

    final ImageView tweenImage = (ImageView) findViewById(R.id.imageView1);
    tweenImage.setBackgroundResource(R.anim.cubicfacetween);      
    tweenImage.post(new Runnable() {
        @Override
        public void run() {
            AnimationDrawable frameAnimation =
                (AnimationDrawable) tweenImage.getBackground();
            frameAnimation.start();
        }
    }
    

    Edit - this question led me to believe that the onWindowFocusChanged method won't always work. It does seem simpler and is probably a better idea if it works for you.

提交回复
热议问题