Android - Better Approach in Loading SD CARD Images

南笙酒味 提交于 2019-12-23 04:29:40

问题


What is a better algorithm on loading or populating images from SD CARD, than storing each image path as Constants?

public final class Constants {

        public static final String[] IMAGES = new String[] {
            // Heavy images
        "file:///mnt/sdcard/folder/folder/folder/1.jpg",
        "file:///mnt/sdcard/folder/folder/folder/2.jpg",
        "file:///mnt/sdcard/folder/folder/folder/3.jpg",
        "file:///mnt/sdcard/folder/4.jpg",
        );
}

Basically I am learning the Universal Image Loader, and focusing on the grid view implementation in loading images. Right now the project is running but it is using the CONSTANT path. The thing is my images is stored in sd card.

LINK: https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/sample/src/com/nostra13/example/universalimageloader/ImageGridActivity.java

LINK2: STORING PATH IN CONSTANT Strings https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/sample/src/com/nostra13/example/universalimageloader/Constants.java


回答1:


If it's a fixed set of images that never change that you know in advance, I don't see any problems with storing references to them in a String array, that's probably the best way to do it.

If you want to dynamically find images on the SD card at run-time you'd be better off scanning/getting a file list of the particular folder or folders you are interested in and passing that to the Image Loader. You can query the MediaStore or you can use Java IO methods.

There are many examples of SO how to do this:

  • https://stackoverflow.com/a/9531063/833647

Either way, Universal Image Loader should take a lot of the heavy-lifting on the bitmap-display side, so I wouldn't worry too much about that.



来源:https://stackoverflow.com/questions/17420664/android-better-approach-in-loading-sd-card-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!