AnimationDrawable not working in Android 2.2

I am using AnimationDrawable as follows:

ImageView rocketImage = (ImageView) layout.findViewById(R.id.animation); rocketImage.setBackgroundResource(R.drawable.progress_blue_animation); rocketAnimation = (AnimationDrawable) rocketImage.getBackground(); rocketAnimation.start(); 

This code works in Android 3.0 / 4.0 / 4.1 / 4.0, but does not work in Android 2.2. How to solve this problem?

+6
source share
2 answers

As far as I know, this is a bug in 2.1, 2.2

A possible workaround might be:

 ImageView rocketImage = (ImageView) layout.findViewById(R.id.animation); rocketImage.setBackgroundResource(R.drawable.progress_blue_animation); rocketAnimation = (AnimationDrawable) rocketImage.getBackground(); rocketImage.post(new Runnable(){ public void run(){ rocketAnimation.start(); } }); 

(But I have not tried it in Targets> 2.1)

+17
source
 view.post(new Runnable() { public void run() { anim.start(); } }); view.startAnimation(anim); 

it works for me.

0
source

Source: https://habr.com/ru/post/919981/


All Articles