0
フェードインした画像の数を表示したい場合は、うまくいきますが、一度完了すると画像が繰り返されません。 私はループでショーをしたい、私は何が欠けている得ていない誰もそれについてのアイデアを持っていますか?一度終了すると画像が繰り返されない
私のコードは
animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.anim_fade_in);
animationFadeOut = AnimationUtils.loadAnimation(this, R.anim.anim_fade_out);
Animation.AnimationListener animListener = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
changeImage(animation);
}
};
// Set listener to animation
animationFadeIn.setAnimationListener(animListener);
animationFadeOut.setAnimationListener(animListener);
// Start fade-in animation
imgBanner.setImageResource(R.mipmap.banner1);
imgBanner.startAnimation(animationFadeIn);
public void changeImage(Animation animation) {
if (animation == animationFadeIn) {
// Start fade-out animation
imgBanner.startAnimation(animationFadeOut);
} else if (animation == animationFadeOut) {
count++;
// Set next image after fading out previous image
switch (count) {
case 1:
imgBanner.setImageResource(R.mipmap.banner2);
imgBanner.startAnimation(animationFadeIn);
break;
case 2:
imgBanner.setImageResource(R.mipmap.banner3);
imgBanner.startAnimation(animationFadeIn);
break;
case 3:
imgBanner.setImageResource(R.mipmap.banner4);
imgBanner.startAnimation(animationFadeIn);
break;
case 4:
imgBanner.setImageResource(R.mipmap.banner5);
imgBanner.startAnimation(animationFadeIn);
break;
default:
break;
}
}
}
anim_fade_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<alpha
android:duration="2000"
android:fromAlpha="0.1"
android:toAlpha="1.0" />
</set>
anim_fade_out.xml
MainActivity.java以下のように見えています
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<alpha
android:duration="2000"
android:fromAlpha="1.0"
android:toAlpha="0.1" />
</set>