我正在尝试写一个非常基本的android应用程序,在屏幕上一个接一个地显示大约5张图片。我希望它在大约10秒后显示一张不同的图片。有没有人能建议我如何解决这个问题。下面我已经概述了我将寻找什么。
图1
图2
图3
图4
图5
显示全屏图片1
等待10秒
删除图片1并显示图片2
等待10秒
删除图片2并显示图片3
等待10秒
删除图片3并显示图片4
等待10秒
删除图片4并显示图片5
等待10秒
重新开始
发布于 2011-05-25 22:28:04
您是否考虑过使用Frame Animations
您可以在包含逐帧动画的动画文件夹中指定xml,指定每个图像的持续时间和其他设置,请检查它
更新
当然,您也可以通过编程方式构建帧动画:
AnimationDrawable animation = new AnimationDrawable();
animation.addFrame(getResources().getDrawable(R.drawable.image1), 100);
animation.addFrame(getResources().getDrawable(R.drawable.image2), 500);
animation.addFrame(getResources().getDrawable(R.drawable.image3), 300);
animation.setOneShot(false);
ImageView imageAnim = (ImageView) findViewById(R.id.img);
imageAnim.setBackgroundDrawable(animation);
// start the animation!
animation.start()发布于 2011-05-25 22:42:00
您可以使用CountDownTimer:请执行以下步骤:
1)声明一个包含图片标识的array
2)如下声明CountDownTimer:
int i=0;
new CountDownTimer(10000,1000) {
@Override
public void onTick(long millisUntilFinished) {}
@Override
public void onFinish() {
imgView.setImageDrawable(sdk.getContext().getResources().getDrawable(array[i]));
i++;
if(i== array.length-1) i=0;
start();
}
}.start();发布于 2015-04-22 23:26:13
创建blink.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/Picture_1" android:duration="10000" />
<item android:drawable="@drawable/Picture_2" android:duration="10000" />
<item android:drawable="@drawable/Picture_3" android:duration="10000" />
<item android:drawable="@drawable/Picture_4" android:duration="10000" />
<item android:drawable="@drawable/Picture_5" android:duration="10000" />
</animation-list>将blink.xml放在可绘制文件夹中,并在活动代码中写下这段代码。
ImageView mImageView ;
mImageView = (ImageView)findViewById(R.id.imageView); //this is your imageView
mImageView .setImageDrawable(getResources().getDrawable( R.drawable.blink));然后你就会得到你想要的。!
https://stackoverflow.com/questions/6125936
复制相似问题