android-universal-image-loader的使用
2013-08-22 17:06
441 查看
温故而知新,方可学而用
开源第三方框架 android-universal-image-loader简介
多线程异步图像加载,缓存和显示
属性设置
//设置图片在下载期间显示的图片
showStubImage(R.drawable.ic_launcher)
//设置图片Uri为空或是错误的时候显示的图片
showImageForEmptyUri(R.drawable.ic_empty)
//设置图片加载/解码过程中错误时候显示的图片
showImageOnFail(R.drawable.ic_error)
//设置图片在下载前是否重置,复位
resetViewBeforeLoading()
//设置下载的图片是否缓存在内存中
cacheInMemory()
//设置下载的图片是否缓存在SD卡中
cacheOnDisc()
//设置图片的解码类型
bitmapConfig(Bitmap.Config.RGB_565)
//设置图片的解码配置
decodingOptions(android.graphics.BitmapFactory.Options decodingOptions)
//设置图片下载前的延迟
delayBeforeLoading(int delayInMillis)
//设置额外的内容给ImageDownloader
extraForDownloader(Object extra)
//设置图片加入缓存前,对bitmap进行设置
preProcessor(BitmapProcessor preProcessor)
//设置显示前的图片,显示后这个图片一直保留在缓存中
postProcessor(BitmapProcessor postProcessor)
//设置图片以如何的编码方式显示
imageScaleType(ImageScaleType imageScaleType)
使用:
1. 创建继承Application的类 在Oncread中初始化
public static void initImageLoader(Context context) {
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO)
.enableLogging() // Not necessary in common
.build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);
}
2 在图片加载的activity中 创建
ImageLoader 、DisplayImageOptions对象
imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder()
// .showStubImage(R.drawable.food)//设置图片在下载期间显示的图片
// .showImageForEmptyUri(R.drawable.food)//设置图片Uri为空或是错误的时候显示的图片
// .showImageOnFail(R.drawable.food)//设置图片加载/解码过程中错误时候显示的图片
.cacheInMemory()//设置下载的图片是否缓存在内存中
.cacheOnDisc()//设置下载的图片是否缓存在SD卡中
.bitmapConfig(Bitmap.Config.RGB_565)//设置图片的解码类型
.build();
gridViewleft = (GridView)findViewById(R.id.gridview_left);
context = this;
3 显示图片
imageLoader.displayImage(position, imageview, options);
简单的三步就可以实现多线程下图片的下载并缓存显示,无须考虑OOM问题
开源第三方框架 android-universal-image-loader简介
多线程异步图像加载,缓存和显示
属性设置
//设置图片在下载期间显示的图片
showStubImage(R.drawable.ic_launcher)
//设置图片Uri为空或是错误的时候显示的图片
showImageForEmptyUri(R.drawable.ic_empty)
//设置图片加载/解码过程中错误时候显示的图片
showImageOnFail(R.drawable.ic_error)
//设置图片在下载前是否重置,复位
resetViewBeforeLoading()
//设置下载的图片是否缓存在内存中
cacheInMemory()
//设置下载的图片是否缓存在SD卡中
cacheOnDisc()
//设置图片的解码类型
bitmapConfig(Bitmap.Config.RGB_565)
//设置图片的解码配置
decodingOptions(android.graphics.BitmapFactory.Options decodingOptions)
//设置图片下载前的延迟
delayBeforeLoading(int delayInMillis)
//设置额外的内容给ImageDownloader
extraForDownloader(Object extra)
//设置图片加入缓存前,对bitmap进行设置
preProcessor(BitmapProcessor preProcessor)
//设置显示前的图片,显示后这个图片一直保留在缓存中
postProcessor(BitmapProcessor postProcessor)
//设置图片以如何的编码方式显示
imageScaleType(ImageScaleType imageScaleType)
使用:
1. 创建继承Application的类 在Oncread中初始化
public static void initImageLoader(Context context) {
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO)
.enableLogging() // Not necessary in common
.build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);
}
2 在图片加载的activity中 创建
ImageLoader 、DisplayImageOptions对象
imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder()
// .showStubImage(R.drawable.food)//设置图片在下载期间显示的图片
// .showImageForEmptyUri(R.drawable.food)//设置图片Uri为空或是错误的时候显示的图片
// .showImageOnFail(R.drawable.food)//设置图片加载/解码过程中错误时候显示的图片
.cacheInMemory()//设置下载的图片是否缓存在内存中
.cacheOnDisc()//设置下载的图片是否缓存在SD卡中
.bitmapConfig(Bitmap.Config.RGB_565)//设置图片的解码类型
.build();
gridViewleft = (GridView)findViewById(R.id.gridview_left);
context = this;
3 显示图片
imageLoader.displayImage(position, imageview, options);
简单的三步就可以实现多线程下图片的下载并缓存显示,无须考虑OOM问题
相关文章推荐
- (源代码分析)Android-Universal-Image-Loader (图片异步载入缓存库)的使用配置
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- 使用Android-Universal-Image-Loader加载图片
- Android 使用图片异步载入框架Universal Image Loader的问题
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- Android 使用Universal Image Loader绘制带圆角的图片(一)
- Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)
- Android第三方框架universal-image-loader[图片缓存加载]及其OOM问题处理【常用】,CardView使用[给列表中项+边框]
- android Universal-Image-Loader 图片异步加载类库的使用(超详细配置)
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- Android 使用Android-Universal-Image-Loader进行异步数据加载
- Android 开源框架Universal-Image-Loader全然解析(一)--- 基本介绍及使用