AnimationDrawable在Android 2.2中不起作用

Ant*_*ton 6 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();
Run Code Online (Sandbox Code Playgroud)

此代码适用于Android 3.0/4.0/4.1/4.0,但在Android 2.2中不起作用.如何解决这个问题呢?

lhl*_*mgr 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();
    }
});
Run Code Online (Sandbox Code Playgroud)

(但我没有在目标> 2.1中尝试它)

  • 我想使用弹出窗口显示加载动画.实际上它适用于4.0,但不能在2.3.3上运行.我尝试了很多东西,比如使用另一个线程,post方法等,没有解决问题.在2.3.3上它只显示第一张图像.怎么解决这个? (3认同)