Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AnimationDrawable don't work in Android 2.2

I using AnimationDrawable like this:

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

This code work in Android 3.0/4.0/4.1/4.0, but don't work in Android 2.2. How to solve this problem?

like image 590
Anton Avatar asked Jul 08 '12 17:07

Anton


1 Answers

As far as i know, thats a Bug in 2.1, 2.2

A possible workaround could 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 didn't try it in Targets >2.1)

like image 91
lhlmgr Avatar answered Sep 19 '22 00:09

lhlmgr