いくつかの画像をアニメーション化したいと思います。この最初のコードが機能しないのに、2番目のコードは機能する理由を誰かに教えてもらえますか?そして、2番目のものを使用する必要がある場合、実行可能なアニメーションを停止するにはどうすればよいですか?
編集:最初のコードは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 ?