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) {
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值