use ImageSwitcher instead of ImageView , which support it on their own. see this example:
http://www.java2s.com/Code/Android/UI/UsingImageSwitcher.htm
you can add animation as follows:
imageSwitcher.setInAnimation(fadeInAnimation); imageSwitcher.setOutAnimation(fadeOutAnimation);
// my test:
public class IntroActivity extends Activity implements ViewFactory { private static final String TAG = "IntroActivity"; private final int[] images = { R.drawable.img3, R.drawable.img2, R.drawable.img1, R.drawable.img4, R.drawable.img5, R.drawable.img6, R.drawable.img7, R.drawable.img8 }; private int index = 0; private final int interval = 10000; private boolean isRunning = true; @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.activity_intro); startAnimatedBackground(); } private void startAnimatedBackground() { Animation aniIn = AnimationUtils.loadAnimation(this, android.R.anim.fade_in); aniIn.setDuration(3000); Animation aniOut = AnimationUtils.loadAnimation(this, android.R.anim.fade_out); aniOut.setDuration(3000); final ImageSwitcher imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher1); imageSwitcher.setInAnimation(aniIn); imageSwitcher.setOutAnimation(aniOut); imageSwitcher.setFactory(this); imageSwitcher.setImageResource(images[index]); final Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { if (isRunning) { index++; index = index % images.length; Log.d("Intro Screen", "Change Image " + index); imageSwitcher.setImageResource(images[index]); handler.postDelayed(this, interval); } } }; handler.postDelayed(runnable, interval); } @Override public View makeView() { ImageView imageView = new ImageView(this); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setLayoutParams(new ImageSwitcher.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); return imageView; } @Override public void finish() { isRunning = false; super.finish(); } }
to start the next activity, in @Override public void run() { if (isRunning) {
just check the index, if the index is 1, then start the next operation and complete the current one;
source share