1

ここで質問するのは初めてです...誰かが私を助けてくれることを願っています....

と としてアニメーション化する複数の画像をアニメーション化しfade inたいfade out。私は1つのイメージビューをアニメーション化することができましたが、最初のイメージビューがフェードアウトすると、2番目のイメージビューがフェードインする必要があります...

アプリケーションが開かれるとループするはずです。ありがとう

これが私のJava onCreate()でアニメーションを呼び出す方法です。

   final ImageView image = (ImageView)findViewById(R.id.bsc);
   final Animation animationFadeIn = AnimationUtils.loadAnimation(this,     R.anim.fadein);
   image.startAnimation(animationFadeIn);
   final Animation animationFadeOut = AnimationUtils.loadAnimation(this, R.anim.fadeout);
image.startAnimation(animationFadeOut);

フェードイン.xml

      <?xml version="1.0" encoding="utf-8"?>
     <set xmlns:android="http://schemas.android.com/apk/res/android"
       android:interpolator="@android:anim/linear_interpolator">
      <alpha 
         android:fromAlpha="0.1" 
         android:toAlpha="1.0" 
         android:duration="2000" 
         />
    </set>  

フェードアウト.xml

     <?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
<alpha 
    android:fromAlpha="1.0" 
    android:toAlpha="0.1" 
    android:duration="2000" 
    />
 </set>
4

2 に答える 2

2

AnimationListener を使用してみてください。

final ImageView image = (ImageView)findViewById(R.id.bsc);
final Animation animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.fadein);
final Animation animationFadeOut = AnimationUtils.loadAnimation(this, R.anim.fadeout);

AnimationListener animListener = new AnimationListener(){

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            }

        @Override
        public void onAnimationEnd(Animation animation) {
            image.setImageResource(R.drawable.hsc);
            image.startAnimation(animationFadeIn);
        }
    };
image.startAnimation(animationFadeOut);
animationFadeOut.setAnimationListener(animListener);

ループしたい場合は、animationFadeIn にも別のリスナーを配置します。これにより、animationFadeOut が再び開始されます。配列からイメージを選択して表示します。

于 2013-09-03T12:31:21.160 に答える
0

android:src="@drawable/...." Activity.xml レイアウトで新しい ImageView を作成します。この ImageViewの属性を使用していないことに注意してください。

    <ImageView 
        android:id="@+id/uno"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
       />

したがって、Activity.xml には最終的に 2 つの imageView が含まれます。

1.-最初の画像 (コード内のオリジナル)

<ImageView
    android:id="@+id/bsc"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:src="@drawable/your_first_image/>

android:src2.-属性のない新しい画像

 <ImageView 
        android:id="@+id/uno"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
       />

アクティビティ クラス onCreate()で、使用する新しい画像を定義します。もちろん、この画像をドローアブル フォルダーに保存してから、setImageResource()メソッドを使用してドローアブルで画像を設定する必要があります。コードは次のようになります。

ImageView nueva = null;
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         //....your code...
         nueva = (ImageView) findViewById(R.id.uno);
         //Here set the new image 
         nueva.setImageResource(R.drawable.your_new_image);
}

次に、メソッドにアニメーションを追加する必要があります。onResume()たとえば、次のようになります。

@Override
    protected void onResume() {
           super.onResume();
          //the imagen you are using in your code
           image.startAnimation(animationFadeOut);
           //the new image fadein
           nueva.startAnimation(animationFadeIn);


    }
于 2014-03-29T21:53:34.217 に答える