简体   繁体   English

如何用计时器更改图像

[英]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. 大家好我有图像说image1和image2我想在计时器上显示两个图像,一次只能看到一个图像。 Both images are overlapped, meaning, image1 is over image2. 两个图像都是重叠的,这意味着,image1在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 我希望我对自己的问题很清楚

Put your images in Drawable folder. 将您的图像放在Drawable文件夹中。 and create an splash.xml file in drawable folder like this : 并在drawable文件夹中创建一个splash.xml文件,如下所示:

<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();

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM