AnimationDrawable在Android 2.2中不起作用

时间:2012-07-08 17:19:52

标签: android drawable android-animation

我像这样使用AnimationDrawable:

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

此代码适用于Android 3.0 / 4.0 / 4.1 / 4.0,但在Android 2.2中无效。如何解决这个问题?

2 个答案:

答案 0 :(得分:17)

据我所知,那是2.1,2.2中的Bug

可能的解决方法可能是:

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();
    }
});

(但我没有在Targets> 2.1中尝试)

答案 1 :(得分:0)

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

这适合我。