安卓每10秒更换一次图片

Im trying to write a very basic android app that displays around 5 pictures one after each other on the screen. I want it to display a different picture after about 10 seconds. Can anyone advise me on how I would go around this. Below i have outlined what i would be looking for.

Picture 1
Picture 2
Picture 3
Picture 4
Picture 5

display full screen Picture 1
wait 10 seconds
Remove Picture 1 and Display Picture 2
Wait 10 seconds
Remove Picture 2 and Display Picture 3
Wait 10 seconds
Remove Picture 3 and Display Picture 4
Wait 10 seconds
Remove Picture 4 and Display Picture 5
Wait 10 seconds

Start again

#0

Have you considered using Frame Animations?

You can specify an xml in your anim folder that contains a frame-by-frame animation, specifing each image duration, and other settings, check it out

UPDATE

You can also build a frame animation programmatically of course:

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

#1

you can use the CountDownTimer : follow these steps :

1) declare an array which will contain the identifients of your pictures

2 ) declare the CountDownTimer like this :

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

#2

create 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>

put blink.xml in drawable folder and in activity Code write this.

ImageView mImageView ;
mImageView = (ImageView)findViewById(R.id.imageView); //this is your imageView
mImageView .setImageDrawable(getResources().getDrawable( R.drawable.blink));

then you will get what you want.!

#3

Create a Runnable that executes the change you want (I suppose it will be changing an ImageView's bitmap/drawable), and post them with delay to the main thread loop, using a Handler and its postDelayed() method.

To make it a loop, you could have the runnable post itself.

推荐文章

自定义表中的单元格

自定义表中的单元格

推荐文章

嵌套集模型,按类别计数项

嵌套集模型,按类别计数项

推荐文章

数据网格内的下拉列表

数据网格内的下拉列表

推荐文章

如何通过编程确定我的iPhone应用程序已被电话中断?

如何通过编程确定我的iPhone应用程序已被电话中断?

推荐文章

从.NET C调用BizTalk管道组件#

从.NET C调用BizTalk管道组件#

推荐文章

Azure表存储数据一致性

Azure表存储数据一致性

推荐文章

RAD-Websphere应用服务器将不启动

RAD-Websphere应用服务器将不启动

推荐文章

如何在javascript中获取DOM元素的HTML

如何在javascript中获取DOM元素的HTML

推荐文章

LNK2019问题

LNK2019问题

推荐文章

Visual Studio和C以及Web开发人员生产力工具/帮助

Visual Studio和C以及Web开发人员生产力工具/帮助

推荐文章

.NET Webservice不再返回JSON数据

.NET Webservice不再返回JSON数据

推荐文章

向Objects.filter添加额外参数(通过Dict)?

向Objects.filter添加额外参数(通过Dict)?

推荐文章

向我解释不同的JSF组件库

向我解释不同的JSF组件库

推荐文章

从click重新分配click事件(使用jQuery)

从click重新分配click事件(使用jQuery)

推荐文章

len(object)或hasattr(object,iter)?

len(object)或hasattr(object,iter)?

推荐文章

将数组作为url参数传递

将数组作为url参数传递