Shishir.bobby
Shishir.bobby

Reputation: 10984

how to change images with timer

Hi all I have to images say image1 and image2 I want to display both images on timer, only one image should be visible at a time. Both images are overlapped, meaning, image1 is over image2.

So, if I use timer, I want to be able to show one image at a time. How do I do this. I hope I am clear with my problem

Upvotes: 3

Views: 5272

Answers (2)

Jana
Jana

Reputation: 2920

The code does not changes from first image to next.

is any thing wrong withthis code?

final ImageView splashImage = (ImageView) findViewById(R.id.ImageView01);
     splashImage.setBackgroundResource(R.drawable.splash);
     AnimationDrawable splashAnimation = (AnimationDrawable) splashImage.getBackground();
     splashAnimation.start();

Upvotes: 1

Nishant Shah
Nishant Shah

Reputation: 3442

Put your images in Drawable folder. and create an splash.xml file in drawable folder like this :

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true"> <item android:drawable="@drawable/splash_1" android:duration="200" /> <item android:drawable="@drawable/splash_2" android:duration="200" /> <item android:drawable="@drawable/splash_3" android:duration="200" /> <item android:drawable="@drawable/splash_4" android:duration="200" /> <item android:drawable="@drawable/splash_5" android:duration="200" /> </animation-list>

and in your activity class

setContentView(R.layout.splashscreen);

    final ImageView splashImage = (ImageView) findViewById(R.splash.ImageView);
    splashImage.setBackgroundResource(R.drawable.splash);
    splashAnimation = (AnimationDrawable) splashImage.getBackground();
    splashAnimation.start();

Upvotes: 9

Related Questions