0

目前我的代码显示来自文件路径的单个图像(在 SDCard 中)。这是目前的onCreate()方法:

 ImageView imgView01 = (ImageView) findViewById(R.id.imageView1);  
 File dir = new File("/sdcard/WallpapersHD/");
 File file[]=dir.listFiles();
 for (int i=0;i<file.length;i++) {
      Drawable d = (Drawable) Drawable.createFromPath(file[i].toString());
      imgView01.setImageDrawable(d);
      }

我想使用 5 秒的时间延迟一个接一个地显示该特定文件夹中的所有图像。如果我可以为文件夹中的每个图像创建一个新的可绘制对象,我该怎么做?以及如何更改图像ImageView以设置该drawable的路径?

4

2 回答 2

0

为方便起见,您可以使用ImageSwitcher,然后执行以下操作:

    imageSwitcher.postDelayed(
            new Runnable() {
                @Override
                public void run() {
                    i++;
                    imageSwitcher.setImageURI(Uri.fromFile(file[i]));
                    imageSwitcher.postDelayed(this, millisBetweenImages);
                }
            },
            millisBetweenImages);

如果您想将图像保留为可绘制对象,它还有一个 setImageDrawable 方法。

于 2011-11-29T09:24:09.140 回答
0

为每个图像创建一个可绘制对象,然后在 ImageView 中不断更改图像,可能在 Handler 或 TimerTask 中。

于 2011-11-29T08:43:00.263 回答