0

いくつかの画像をアニメーション化したいと思います。この最初のコードが機能しないのに、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 ?
4

1 に答える 1

0

これを試すことができます..このコードは正しく動作します

BitmapDrawable frame1 = (BitmapDrawable)getResources().getDrawable(R.drawable.jth);
BitmapDrawable frame2 = (BitmapDrawable)getResources().getDrawable(R.drawable.jthj);
int duration = 10;
final AnimationDrawable ad = new AnimationDrawable();
ad.setOneShot(false);
ad.addFrame(frame1, duration);
ad.addFrame(frame2, duration);
iv.setBackgroundDrawable(ad);
ad.setVisible(true, true);

ad.start(); を入れます。ボタンの onClickListener と ad.stop(); ストップアニメーション用

于 2012-10-27T11:39:29.430 に答える