首页 > 解决方案 > 通过循环在 imageviewer 中显示多个图像

问题描述

我想在我的 imageView 中显示多个图像我想通过使用 for 循环来做到这一点,但我的图像视图只显示最后一个图像。

我也尝试过 Thread.sleep 和 sleep 功能,但它们不起作用

for(int i=0;i<=3;i++){
                try {

                    pic = picText.getText().toString();
                    String photoPath = "sdcard/Pictures/" + pic + i + ".jpg";
                    imageView.setImageBitmap(BitmapFactory.decodeFile(photoPath));
                    sleep(1000);
                } catch (Exception ex) {

                }}

我希望一个接一个地获取所有图像,延迟在 sleep() 函数中给出。

标签: javaandroidandroid-imageviewandroid-image

解决方案


获取数组或 ArrayList 中的所有图像路径,然后使用处理程序和 timertask

定时器 t; 处理程序处理程序;可运行更新;处理程序 = 新处理程序();update = new Runnable() { @Override public void run() {

            //load photo
        }
    };
    t = new Timer();
           t.schedule(new TimerTask() {
               @Override
               public void run() {
                   handler.post(update);
               }
           }, 0, 5000);
Note if its showing last image, redirect counter to 1st image. Hope this helps

推荐阅读