universal image loader自己使用的一些感受
1、全局入口的Application定义初始化:
ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(getApplicationContext())
.threadPoolSize(3) //线程池内加载的数量
.threadPriority(Thread.NORM_PRIORITY - 1) // default
.denyCacheImageMultipleSizesInMemory()
//.memoryCache(new WeakMemoryCache()) //也可以用自己的内存缓存实
.memoryCache(new LruMemoryCache(50 * 1024 * 1024)) //也可以用自己的内存缓存实现
.memoryCacheSize(50*1024*1024)
.diskCacheFileNameGenerator(new Md5FileNameGenerator()) //将保存的时候的URL名称用MD5加密
.tasksProcessingOrder(QueueProcessingType.FIFO) //先进先出
.diskCacheSize(200 * 1024 * 1024)
.defaultDisplayImageOptions(DisplayImageOptions.createSimple())
.imageDownloader(new BaseImageDownloader(getApplicationContext())) // default
.imageDecoder(new BaseImageDecoder(true)) // default
//.writeDebugLogs() // Remove for release app
.build();
//全局初始化此配置
ImageLoader.getInstance().init(configuration);
2、显示设置:
/**
*用于显示图片的选项,没过渡时间
* 用于圈子社区,解决列表图片过多时,出现刷新闪烁的情况
*/
public static DisplayImageOptions OptionsWithCache = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.icon_no_photo)
.showImageOnFail(R.drawable.icon_no_photo)
.showImageForEmptyUri(R.drawable.icon_no_photo)//设置图片Uri为空或是错误的时候显示的图片
.cacheInMemory(true)
.cacheOnDisk(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.considerExifParams(true)
//EXACTLY_STRETCHED:图片会缩放到目标大小完全相同 EXACTLY :图像将完全按比例缩小的目标大小
//IN_SAMPLE_INT:图像将被二次采样的整数倍
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.resetViewBeforeLoading(false)
// .delayBeforeLoading(50) //载入图片前稍做延时可以提高整体滑动的流畅度
.displayer(new FadeInBitmapDisplayer(200)) //是否图片加载好后渐入的动画时间
.build();
3、如果ImageView设置了长宽大小:
建议用display,可以根据ImageView的大小来自动缩放图片,节省内存:
ImageLoader.getInstance().displayImage(pic_url, imageView,OptionsWithCache);
对于listView里面,图片可能因为滑动过快,导致错误重复,可以通过设置tag来处理:
public static void setImageWithTag(final String pic_url,final ImageView imageView,Context context) {
if(pic_url != null) {
String tag = (String) imageView.getTag();
if(tag == null) {
tag = "";
}
if(pic_url.equals(imageView.getTag())) {
return;
}
}
String picUrl = pic_url;
if(!picUrl.contains("http://")) {
picUrl = MyConfig.picFirst+picUrl;
}
//Log.i("main","loading pic:"+pic_url);
ImageLoader.getInstance().displayImage(picUrl, imageView, OptionsWithCache);
}
listView里面的设置:
SetImageUtils.setImageWithTag(picUrl,holder.iv,context);
holder.iv.setTag(picUrl);
4、一些图片加载过程中的监听:
//加载自定义配置的一个图片的,网络加载监听,等待加载图片完成再初始化缩小放大
ImageLoader.getInstance().displayImage(picurl,mImageView, SetImageUtils.OptionsWithCache, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
super.onLoadingStarted(imageUri, view);
Utility.setLoadingProgressbar(null,parentView,true);
} @Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
Utility.setLoadingProgressbar(null,parentView,false);
}
}, new ImageLoadingProgressListener() {
@Override
public void onProgressUpdate(String s, View view, int i, int i1) {
//Log.i("main","i="+i+",il="+i1);
}
});
主要有ImageLoadingListener(或者其子类),和ImageLoadingProgressListener两种。
对于universal image loader 结合了内存、本地存储二级机制,一定程度上方便了使用,但也有一些问题,有一定几率会OOM,加载网络图片不够快等。
universal image loader自己使用的一些感受的更多相关文章
- 【译】UNIVERSAL IMAGE LOADER. PART 3---ImageLoader详解
在之前的文章,我们重点讲了Android-Universal-Image-Loader的三个主要组件,现在我们终于可以开始使用它了. Android-Universal-Image-Loader有四个 ...
- Android中Universal Image Loader开源框架的简单使用
UIL (Universal Image Loader)aims to provide a powerful, flexible and highly customizable instrument ...
- universal image loader在listview/gridview中滚动时重复加载图片的问题及解决方法
在listview/gridview中使用UIL来display每个item的图片,当图片数量较多需要滑动滚动时会出现卡顿,而且加载过的图片再次上翻后依然会重复加载(显示设置好的加载中图片) 最近在使 ...
- 【Android应用开发】 Universal Image Loader ( 使用简介 | 示例代码解析 )
作者 : 韩曙亮 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/50824912 相关地址介绍 : -- Universal I ...
- android universal image loader 缓冲原理详解
1. 功能介绍 1.1 Android Universal Image Loader Android Universal Image Loader 是一个强大的.可高度定制的图片缓存,本文简称为UIL ...
- 开源项目Universal Image Loader for Android 说明文档 (1) 简介
When developing applications for Android, one often facesthe problem of displaying some graphical ...
- 开源项目Universal Image Loader for Android 说明文档 (1) 简单介绍
When developing applications for Android, one often facesthe problem of displaying some graphical ...
- 【译】UNIVERSAL IMAGE LOADER.PART 2---ImageLoaderConfiguration详解
ImageLoader类中包含了所有操作.他是一个单例,为了获取它的一个单一实例,你需要调用getInstance()方法.在使用ImageLoader来显示图片之前,你需要初始化它的配置-Image ...
- 翻译:Universal Image Loader
本文转载于:http://blog.csdn.net/tianxiangshan/article/details/9399183 All manipulations are held by the I ...
随机推荐
- Java 元注解
元注解@Target,@Retention,@Documented,@Inherited * * @Target 表示该注解用于什么地方,可能的 ElemenetType 参数包括: * Elemen ...
- 轻松创建R语言函数包
讲真,用R这么几年,始终未尝试过写自己的包,看来这就是我与真正程序员的差距了——编程习惯等于没有. 昨天一个偶然的机会想开始写自己的工具包,发现了前期教程的有一些过时.于是,写一个**windows* ...
- HTML5中id可以用数字开头,但在css中不能正常使用
昨晚在看<响应式Web设计:html5和css3实战>时,书中提到“HTML5中的ID指可以用数字开头”.这个还真不知道,于是测试了一下,发现了问题. 在H5描述中是这样说的: 在css样 ...
- 特征处理(Feature Processing)
[本文链接:http://www.cnblogs.com/breezedeus/p/4109456.html,转载请注明出处] 我的博客主营地迁至github,欢迎朋友们有空去看看:http://br ...
- iOS开发零基础--Swift篇 循环
循环的介绍 在开发中经常会需要循环 常见的循环有:for/while/do while. 这里我们只介绍for/while,因为for/while最常见 for循环的写法 最常规写法 // 传统写法 ...
- Keeping Async Methods Alive
Consider a type that will print out a message when it’s finalized, and that has a Dispose method whi ...
- d3 API scale
比例尺有很多种类型,每一种类型都有各自的方法. 常用的是linear log oridinal linear .rangeRound(): 输出的值 四舍五入 .copy():返回一个独立的副本 .t ...
- FreeRTOS和Ucos在任务优先级的区别
而ucos的任务优先级是任务优先级的数组越小,任务优先级越高.和STM32的中断优先级保持一样的分析,和freeRTOS相反.
- java 动态代理示例,带主要注释
Java proxy是基于反射,仅仅支持基于接口的动态代理. java 动态代理是一切架构的基础,必须了解. 废话少说,先上代码获得感性认识. 示例代码有主要注释. 接口: public interf ...
- 在ASP.NET WebAPI 中使用缓存【Redis】
初步看了下CacheCow与OutputCache,感觉还是CacheOutput比较符合自己的要求,使用也很简单 PM>Install-Package Strathweb.CacheOutpu ...