2012-05-11 8 views
0

単純に2つのフレームとループを画面に表示するアニメーション描画可能なオブジェクトを作成しようとしています。Android AnimationDrawableの作成とループ

Handler handler = new Handler(); 
AnimationDrawable mouseani = new AnimationDrawable(); 
ImageView img; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    Drawable mouse1 = getResources().getDrawable(R.drawable.mouse_for_use); 
    Drawable mouse2 = getResources().getDrawable(R.drawable.mouse_for_use_2); 
    mouseani.addFrame(mouse1, 500); 
    mouseani.addFrame(mouse2, 500); 
    img = (ImageView) findViewById(R.id.imgView); 
    img.setBackgroundDrawable(mouseani); 
    mouseani.setCallback(img); 
    mouseani.setVisible(true, true); 
    mouseani.start(); 
    mouseani.stop(); 
} 

ありがとう:

しかし、何らかの理由で私のAnimationdrawableが一つでもラウンドをやっていないし、ちょうどループはもちろん、最初のフレームを示す...ここ

は私のコードです!

答えて

0

あなたが次々とやっているように、あなたは開始したり停止したりすることはできません。アニメーションは、あたかもaysncプロセスであることがあります。

別の方法、たとえばアニメーション描画がフレーム外になったときにリスナーを作成してからアニメーションを呼び出す必要があります。

ここでヒントをご覧ください。 Android AnimationDrawable and knowing when animation ends

関連する問題