문제

Currently my code displays a single image from a file path (in SDCard). This is in onCreate() method for now:

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

I want to display all the images in that particular folder one after the other using a time delay of say 5 seconds. If I can create a new drawable for each image in the folder, How do I do it? and how do I change the image in ImageView to set that drawable's path?

도움이 되었습니까?

해결책

You could use an ImageSwitcher for convenience, and then do:

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

it also has a setImageDrawable-method if you want to keep your images as Drawables.

다른 팁

Create a drawable for each image, and then keep changing the image in your ImageView, perhaps in a Handler or TimerTask.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top