4.2自定义ImageLoader

自定义下载设置

ImageLoaderConfiguration configuration=new ImageLoaderConfiguration.Builder(context)
.threadPoolSize(THREAD_COUNT)
.threadPriority(Thread.NORM_PJRIORITY-PRIORITY)
.denyCacheImageMultipleSizesInMemory() //防止缓存多套尺寸的图片到我们内存中
.memoryCathe(new WeakMemoryCache())//弱因公
.diskCacheSize(DISK_CACHE_SIZE);
.diskCacheFileNameGenerator(new Nd5FileNameGenerator())//使用MD5命名缓存文件
.tasksProcessionOrder(QueueProcessingType.LIFO)//图片下载顺序
.defaultDisplayImageOptions(getDefultOptions())//默认的图片加载options
.imageDownloader(new BaseImageDownloader(context,CONNECTION_TIME_OUT,READ_TIME_OUT))//设置图片下载器
.writeDebugLogs()//debug环境下会输出日志
.build();

ImageLoader.getInstance().init(configeration);
ImageLoader.getInstance();

private DisplayImageOptions getDefaultOptions(){
DisplayImageOptions options=new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.xadsdk_ima_error)//图片地址为空时,默认图片
.showImageOnFail(R.drawable.xadsdk_ima_error) //图片下载失败时显示的图片
.cacheInMemory(true)//设置图片可以缓存在内存
.cacheOnDisk(true)//设置图片可以缓存在硬盘
.bitmapConfig(Bitmap.Config.RGB_565)//使用的图片解码类型
.decodingOptions(new BitmapFacrory.Optins())//图片解码配置


.build();
}
线程数
4
图片加载优先级
2
缓存大小
50*1024
连接超时时间(毫秒)
5*1000
读取超时时间(毫秒)
30*1000

正常的线程优先级Thread.NORM_PJRIORITY

自定义显示设置

DisplayImageOptions options=new DisplayImageOptions.Builder(),build();
imageLoader.displayImage("url",imageView,options,new SimpleImageLoadingListener(){})

监听

new SimpleImageLoadingListener(){

}

imageloader的流程控制

内存

硬盘

网络

Last updated

Was this helpful?