我想为一些图像制作动画。有人能告诉我为什么第一段代码不起作用,而第二段代码起作用吗?如果我必须使用第二个,我如何将动画停止到 runnable 中?
编辑:第一个代码适用于 android 4.x,但不适用于 2.2(模拟器和设备)
代码 1(进入“onCreate()”):
ImageView boule = (ImageView)findViewById(R.id.boule);
boule.setImageBitmap(null);
boule.setBackgroundResource(R.anim.anime);
AnimationDrawable animation = (AnimationDrawable)boule.getBackground();
animation.start();
// does not animate anything...
代码 2(也进入 "onCreate()" ):
ImageView boule = (ImageView)findViewById(R.id.boule);
boule.setImageBitmap(null);
boule.setBackgroundResource( R.anim.anime );
final AnimationDrawable animation = (AnimationDrawable) boule.getBackground();
boule.post(new Runnable() {
public void run() {
if ( animation != null ) animation.start();
}
});
// OK, it works, but how do I stop this ?