2011-06-03 8 views
6

私の質問は、アニメーションリストのアイテムをアニメーション化することは可能ですか?具体的には、あなたが持っていると言う:Androidのアニメーションリストのアニメーション

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true"> 
    <item android:drawable="@drawable/rocket_thrust1" android:duration="200" /> 
    <item android:drawable="@drawable/rocket_thrust2" android:duration="200" /> 
    <item android:drawable="@drawable/rocket_thrust3" android:duration="200" /> 
</animation-list> 

が、私は、各<item>のアルファをフェードではなく、単にある画像から次の画像へジャンプしたい、それは可能ですか?

答えて

3

これを行うには、トゥイーンアニメーションを使用する必要があります。基本的には、現在のイメージ用と新しいイメージ用の2​​つのImageViewオブジェクトが必要です。ビューを切り替えるにはImageSwitcherウィジェットを使用すると

<?xml version="1.0" encoding="utf-8"?> 
<alpha xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromAlpha="0.0" 
    android:toAlpha="1.0" 
    android:startOffset="500" 
    android:duration="500" /> 

<?xml version="1.0" encoding="utf-8"?> 
<alpha xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromAlpha="1.0" 
    android:toAlpha="0.0" 
    android:startOffset="500" 
    android:duration="500" /> 

および解像度/アニメーション/ fadein.xml:RES /アニメーション/ fadeout.xmlための2つのトゥイーンアニメーションを作成

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    LinearLayout ll = new LinearLayout(this); 
    ll.setOrientation(LinearLayout.VERTICAL); 
    setContentView(ll); 
    final ImageSwitcher is = new ImageSwitcher(this); 
    is.setOutAnimation(this, R.anim.fadeout); 
    is.setInAnimation(this, R.anim.fadein); 
    ImageView iv1 = new ImageView(this); 
    iv1.setImageResource(R.drawable.icon); 
    is.addView(iv1); 
    is.showNext(); 
    ll.addView(is); 

    Button b = new Button(this); 
    ll.addView(b); 

    b.setOnClickListener(new OnClickListener() 
    { 

     @Override 
     public void onClick(View v) 
     { 
      ImageView iv2 = new ImageView(MainActivity.this); 
      iv2.setImageResource(R.drawable.icon2); 
      is.addView(iv2); 
      is.showNext(); 
     } 
    }); 
} 

トゥイーンアニメーションについてはmy blogに一連の記事があります。

+0

これが私が探しているものであるかどうかは不明です。私は、アプリがデータをダウンロードしている間にスプラッシュ画面をアニメーション化しようとしているので、単に静的なイメージを持っているわけではありません。アニメーションには最低4枚の画像が含まれ、アニメーションはそれ自身で発生するはずです - ユーザーとのやりとりなし – tomislav2012

+0

ボタンを使用してコードを単純にしました。バックグラウンドスレッドを持つImageSwitcherを使用して、イメージを定期的に変更することができます。 –

関連する問題