2010-08-03 71 views
3

大家好 我要图像说image1和image2 我想在计时器上显示两个图像,一次只能看到一个图像。两个图像都重叠,意味着image1在image2上方。如何用计时器更改图像

所以,如果我使用计时器,我希望能够一次显示一个图像。 我该怎么做。 我希望我清楚我的问题

回答

8

将您的图像放入可绘制文件夹。并创建绘制文件夹中的文件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>

,并在活动类

setContentView(R.layout.splashscreen); 

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

感谢您的回复.. 是不是需要将xml命名为“splash.xml”? 其次,如果我将xml名称更改为某些xyz amd将此xml添加到anim文件夹,那么它会工作吗? 问候 – iscavengers 2010-08-03 10:18:58

+0

是的,你可以设置任何名称。但你不能把它放在anim文件夹中。 – 2010-08-03 10:26:02

+0

但我没有得到1点dis是我的oncreate如何看起来像现在。 setContentView(R.layout.main); \t setContentView(R.layout.spl); \t final ImageView splashImage =(ImageView)findViewById(R.id.majicImgView); \t splashImage.setBackgroundResource(R.drawable.magic_number_white); AnimationDrawable splashAnimation =(AnimationDrawable)splashImage.getBackground(); splashAnimation.start(); 是否有可能hv 2 setContentView? – iscavengers 2010-08-03 11:07:50

1

代码不从第一图像改变未来。

这个代码有什么问题吗?

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

如果动画未启动,请在onWindowFocusChanged()事件中启动动画 – 2010-08-05 04:19:43