How to change images using a timer

Hello everyone. I have images1 and image2 talking to my images. I want to display both images on a timer, only one image should be visible at a time. Both images overlap each other, that is, image1 is on top of image2.

So, if I use a timer, I want to be able to show one image at a time. How should I do it. I hope I understand with my problem.

+3
source share
2 answers

Put the images in the Drawable folder. and create a splash.xml file in a 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();
+8
source

The code does not change from the first image to the next.

- ?

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

Source: https://habr.com/ru/post/1757798/


All Articles