3

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

Eonasdan
  • 7,563
  • 8
  • 55
  • 82
Shishir.bobby
  • 10,994
  • 21
  • 71
  • 100

2 Answers2

9

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();
Christian
  • 25,249
  • 40
  • 134
  • 225
Nishant Shah
  • 3,442
  • 5
  • 25
  • 34
  • Thanks for reply.. is it neceesary to name that xml "splash.xml"?? secondly, if i change xml name to some xyz amd put this xml to anim folder, than will it work??? regards – Shishir.bobby Aug 03 '10 at 10:18
  • yes you can set any name. but you can not put it in anim folder. – Nishant Shah Aug 03 '10 at 10:26
  • but i didnt get 1 point dis is how my oncreate looks like now. setContentView(R.layout.main); setContentView(R.layout.spl); final ImageView splashImage = (ImageView) findViewById(R.id.majicImgView); splashImage.setBackgroundResource(R.drawable.magic_number_white); AnimationDrawable splashAnimation = (AnimationDrawable) splashImage.getBackground(); splashAnimation.start(); is it possible to hv 2 setContentView ???? – Shishir.bobby Aug 03 '10 at 11:07
  • You need to set only setContentView(R.layout.main); and you dont have to specify setContentView(R.layout.spl); – Nishant Shah Aug 03 '10 at 12:12
  • This code works fine no question about it. But I have one issue on my phone. The first time when the animation is played it is slow and after that it starts to works normally it is like the first time it needs time to load the images... Do you have this problem ? Can I solve it somehow ? cause the first time my animation looks ugly and slow – Lukap Aug 16 '12 at 14:03
  • Exactly @Lukap, first time it will take time to load all the images. Once it is loaded it wil work perfectly. Alternate solution is you can use Thread to animate the images one by one. It will not take time, it will render the images one by one. – Nishant Shah Aug 21 '12 at 04:34
1

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();
Jana
  • 2,890
  • 5
  • 35
  • 45