Android中如何实现每10秒钟换一幅图片?

我是一名初学者,正在写一个基础的Android程序,想在一个屏幕中像幻灯片一样显示5张图片。每换一次图片的时间间隔是10秒钟,一直循环下去。大家谁能告诉我这个程序如何实现,谢谢。

你可以使用CountDownTimer()方法,由以下两步实现:
1) 声明一些数组,这些数组包含你图片的标识符,
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) i=0;
                    start();
                }
            }.start();

你可以创建帧动画来实现:

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

可以使用线程来实现,开启一个线程,每隔10秒给Handler发送一个消息,Handler接受到消息后更改图片。

public void run() {
    while(true){
        try {
            mReadDataHandler.sendEmptyMessage(0);
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class ReadDataHandler extends Handler{
    @Override
    public void handleMessage(Message msg) {
imgView.setImageDrawable(sdk.getContext().getResources().getDrawable(array[i]));
                i++;
                if(i >= array.length){
                     i = 0;
                }
        super.handleMessage(msg);
    }

}

Handler + Message 可以使用