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-7311练习(上)
java练习,仅供参考! 欢迎同学们交流讨论. JDK 1.8 API帮助文档 JDK 1.6 API中文文档 Java GUI -------------------------2016-10-23 ...
- 使用sklearn进行集成学习——理论
系列 <使用sklearn进行集成学习——理论> <使用sklearn进行集成学习——实践> 目录 1 前言2 集成学习是什么?3 偏差和方差 3.1 模型的偏差和方差是什么? ...
- html form 提交表单的一些问题
1. 如果在一个form里有summit按钮,则只能提交本form的内容
- IOS中CoreData浅析
CoreData简介: 什么是CoreData? Core Data是iOS5之后才出现的一个框架,它提供了对象-关系映射(ORM)的功能,即能够将OC对象转化成数据,保存在SQLite数据库文件中, ...
- Form表单提交数据的几种方式
一.submit提交 在form标签中添加Action(提交的地址)和method(post),且有一个submit按钮(<input type='submit'>)就可以进行数据的提交, ...
- 日常工作中的点滴:C# 根据字节长度截包含中文的字符串
方法中利用正则表达式判断某个字符是否是中文 public string SubStringB(string text,int length){ int target=0; int b=0; for(i ...
- php CLI 模式下的传参方法
在CLI模式(命令行界面 Command Line Interface)下,传入参数有如下3种方法: 一. getopt函数(PHP 4 >= 4.3.0, PHP 5) getopt - 从命 ...
- (原创) 巩固理解I2C协议(MCU,经验)
题外话:这几天天气突然转冷了.今天已是11月23日了,查查黄历,昨天(11月22日)刚好是小雪,一夜温度骤降,果然老祖先的经验有灵验!冬天来了,还是多加加衣服,注意保暖! 1.Abstract ...
- 申请Google API Key
想使用google map api 必须从google网站上获取key之后才有权限使用,但是要想申请key必须要有证明书,也就是所谓的MD5.下面一步一步来说明: 步骤1: 如果你使用的是eclips ...
- linux-11 基本命令之 -工作期目录切换命令-pwd,cd,
pwd 命令用于显示当前的工作目录,格式为:pwd[选项] @1.查看当前的工作路径: [root@localhost /]# pwd cd 命令用于切换工作路径 格式为:"cd 目录名称& ...