android 平台上加载、缓存,显示图片的开源代码Android-Universal-Image-Loader

Android-Universal-Image-Loader
android 平台上加载、缓存,显示图片的开源代码(Powerful and flexible library for loading, caching and displaying images on Android.)

1)支持多线程下载图片。
2)支持imageCache.
3)支持diskCache.

下载地址:https://github.com/nostra13/Android-Universal-Image-Loader
里面有example:  imagePagerActivity.java

使用方法:

//先设置imageLoader的属性 cacheOnDisk/  memoryCache 等
options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
.resetViewBeforeLoading(true)
.cacheOnDisk(true)
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.considerExifParams(true)
.displayer(new FadeInBitmapDisplayer(300))
.build();

//显示指定URL的image,里面可能会cache image,或者从cache中取image
imageLoader.displayImage(images[position], imageView, options, new SimpleImageLoadingListener()

//实现onLoadingStarted()/onLoadingFailed()/onLoadingComplete()等回调函数

DefaultConfigurationFactory.java 中设置
//默认的memoryCacheSize 为当前可用内存的1/8
/**
* Creates default implementation of {@link MemoryCache} - {@link LruMemoryCache}<br />
* Default cache size = 1/8 of available app memory.
*/
public static MemoryCache createMemoryCache(int memoryCacheSize) {
if (memoryCacheSize == 0) {
memoryCacheSize = (int) (Runtime.getRuntime().maxMemory() / 8);
}
return new LruMemoryCache(memoryCacheSize);
}

/** Creates reserve disk cache folder which will be used if primary disk cache folder becomes unavailable */
private static File createReserveDiskCacheDir(Context context) {

你可能感兴趣的:(android 平台上加载、缓存,显示图片的开源代码Android-Universal-Image-Loader)