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自己使用的一些感受的更多相关文章

  1. 【译】UNIVERSAL IMAGE LOADER. PART 3---ImageLoader详解

    在之前的文章,我们重点讲了Android-Universal-Image-Loader的三个主要组件,现在我们终于可以开始使用它了. Android-Universal-Image-Loader有四个 ...

  2. Android中Universal Image Loader开源框架的简单使用

    UIL (Universal Image Loader)aims to provide a powerful, flexible and highly customizable instrument ...

  3. universal image loader在listview/gridview中滚动时重复加载图片的问题及解决方法

    在listview/gridview中使用UIL来display每个item的图片,当图片数量较多需要滑动滚动时会出现卡顿,而且加载过的图片再次上翻后依然会重复加载(显示设置好的加载中图片) 最近在使 ...

  4. 【Android应用开发】 Universal Image Loader ( 使用简介 | 示例代码解析 )

    作者 : 韩曙亮 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/50824912 相关地址介绍 : -- Universal I ...

  5. android universal image loader 缓冲原理详解

    1. 功能介绍 1.1 Android Universal Image Loader Android Universal Image Loader 是一个强大的.可高度定制的图片缓存,本文简称为UIL ...

  6. 开源项目Universal Image Loader for Android 说明文档 (1) 简介

     When developing applications for Android, one often facesthe problem of displaying some graphical ...

  7. 开源项目Universal Image Loader for Android 说明文档 (1) 简单介绍

     When developing applications for Android, one often facesthe problem of displaying some graphical ...

  8. 【译】UNIVERSAL IMAGE LOADER.PART 2---ImageLoaderConfiguration详解

    ImageLoader类中包含了所有操作.他是一个单例,为了获取它的一个单一实例,你需要调用getInstance()方法.在使用ImageLoader来显示图片之前,你需要初始化它的配置-Image ...

  9. 翻译:Universal Image Loader

    本文转载于:http://blog.csdn.net/tianxiangshan/article/details/9399183 All manipulations are held by the I ...

随机推荐

  1. nginx 配置rewrite 笔记

    nginx 配置rewrite笔记: 通过下面的示例来说明一下,1. 先说说location : location 表示匹配传入的url地址,其中配置符有多种,各种情况的意义不一样: location ...

  2. HTML5实战1

    第一章 1.搭建环境,wamp 2.检查浏览器是否支持html5 ,是否支持新标签<canvas></canvas> 3.简单高效,少用id,多用标签. 4.使用css3美化样 ...

  3. ADO.NET Entity Framework

    ADO.NET Entity Framework 是微软以 ADO.NET 为基础所发展出来的对象关系对应 (O/R Mapping) 解决方案, 早期被称为 ObjectSpace,现已经包含在 V ...

  4. bzoj 3110

    题意:戳这里 思路:可以用cdq分治(很明显这种模型妹纸分治法很解决)..不过为了学习树套树特地写了一下.. 所谓的树套树也第一层(最外层)普通的维护的是一个node,而树套树维护的是一个数据结构(一 ...

  5. 【设计模式之装饰者模式InJava】

    需求:定义一个操作系统OS接口,安装Windows10操作系统,在上面安装虚拟机VMWare,虚拟机里装Linux; 然后在Linux中安装虚拟机VMware,再在虚拟机里安装MacOS操作系统. 实 ...

  6. halcon读取一张照片,并转化为灰度图像

    dev_close_window () read_image (Image, 'E:/图片/123.jpg') get_image_size (Image, Width, Height) dev_op ...

  7. Kernels

    Let \(E\) be a set and  \(\mathscr{E}\)  a \(\sigma\)-algebra of subsets of  \(E\). Assume that the ...

  8. 在Linux上用supervisor运行ASP.NET Core站点的一个坑

    将一个ASP.NET Core站点在Linux服务器上以self-contained部署方式发布出来后,直接在终端上运行下面的命令,站点可以正常运行. /data/AboutUs/bin/Debug/ ...

  9. java 多线程(synchronized)

    package com.example; public class App { public static void main(String[] args) { doRunable dr = new ...

  10. [异常解决] 初玩SAE遇到的小问题——注册&创建项目+MyEclipse装插件直接部署+一个简单的JSP部署实现

    ① 新浪SAE快速上手教程:http://jingyan.baidu.com/season/43090 上面一个链接是针对PHP的相关介绍,如果用java还有点不一样,具体请看新浪SAE官网:http ...