问题
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