0
我想動畫一些圖片。 有人能告訴我爲什麼這第一段代碼不起作用,但第二段有效嗎? 如果我必須使用第二個,我該如何停止動畫進入可運行?android frame by frame動畫 - 與這兩個代碼的區別
編輯:第一代碼適用於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 ?
謝謝,夏爾,但它不工作。我已經把所有的代碼放在了onCreate方法中(用我自己替換資源後),然後在下面添加「ad.start()」,並且......什麼也沒有發生。我只看到第一張圖片。 – Chrysotribax