ImageLoader must be init with configuration before using
遇到上面的问题是没有全局初使化ImageLoader,我是在Application中配置了ImageLoaderConfiguration 解决的,当然还有官方的写法
public class MyApplication extends Application {
private MyApplication instance;
@Override
public void onCreate() {
super.onCreate();
instance = this;
initImageloader();
}
public void initImageloader() {
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_picture_loading)
.showImageOnFail(R.drawable.ic_picture_loadfailed)
.resetViewBeforeLoading(false) // default
.delayBeforeLoading(0).cacheInMemory(true) // default
.cacheOnDisk(true) // default
.considerExifParams(true) // default
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default
.bitmapConfig(Bitmap.Config.ARGB_8888) // default
.displayer(new SimpleBitmapDisplayer()) // default
.handler(new Handler()) // default
.build();
File picPath = new File(Environment.getExternalStorageDirectory().getPath() + File.separator + "MyApp"+ File.separator + "files");
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).memoryCacheExtraOptions(480, 800) //我是用的这种写法
// default = device screen dimensions
.diskCacheExtraOptions(480, 800, null).threadPoolSize(3)
// default
.threadPriority(Thread.NORM_PRIORITY - 1)
// default
.tasksProcessingOrder(QueueProcessingType.FIFO)
// default
.denyCacheImageMultipleSizesInMemory().memoryCache(new LruMemoryCache(2 * 1024 * 1024))
.memoryCacheSize(2 * 1024 * 1024).memoryCacheSizePercentage(13)
// default
.diskCache(new UnlimitedDiskCache(picPath))
// default
.diskCacheSize(50 * 1024 * 1024).diskCacheFileCount(1000)
.diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
// default
.imageDownloader(new BaseImageDownloader(getApplicationContext())) // default
.imageDecoder(new BaseImageDecoder(true)) // default
.defaultDisplayImageOptions(options) // default
.writeDebugLogs().build();
ImageLoader.getInstance().init(config);
}
}
因为Application是应用生命周期最长的,它是单例的,用来交互Activity和Service的数据,ImageLoaderConfiguration使用了建造者模式配置参数,设置了线程池中线程个数,内存存储大小,数量,硬盘存储大小,数量等参数。
开发过程中用到了开源项目Android-Universal-Image-Loader,Universal-Image-Loader,一个强大的图片加载框架,具有以下的特性:
1、多线程下载图片,图片可以来源于网络,文件系统,项目文件夹assets中以及drawable中等
2、支持随意的配置ImageLoader,例如线程池,图片下载器,内存缓存策略,硬盘缓存策略,图片显示选项以及其他的一些配置
3、支持图片的内存缓存,文件系统缓存或者SD卡缓存
4、支持图片下载过程的监听
5、根据控件(ImageView)的大小对Bitmap进行裁剪,减少Bitmap占用过多的内存
6、较好的控制图片的加载过程,例如暂停图片加载,重新开始加载图片,一般使用在ListView,GridView中,滑动过程中暂停加载图片,停止滑动的时候去加载图片
7、提供在较慢的网络下对图片进行加载
ImageLoader must be init with configuration before using的更多相关文章
- ImageLoader简单使用
效果图就是一个从网络加载的图片:在加载的时候图片的中间显示一个进度条 数据是随便找的一个网络图片的地址 导入jar包universal-image-loader-1.9.5 用来展示商品使用 在 ...
- Android 黑色样式menu
效果图:
- ImageLoader作用 AAAA
https://github.com/nostra13/Android-Universal-Image-Loader ImageLoader作用 1.多线程下载图片,图片可以来源于网络,文件系统,项目 ...
- ImageLoader简介和使用方法
1.功能概要 Android-Universal-Image-Loader是一个开源的UI组件程序,该项目的目的是提供一个可重复使用的仪器为异步图像加载,缓存和显示. (1).使用多线程加载图片(2) ...
- Android ImageLoader(Android-Universal-Image-Loader)【1】概述及使用简单介绍
Android ImageLoader(Android-Universal-Image-Loader)[1]概述及使用简单介绍 一,前言:为什么要引入Android-Universal-Imag ...
- linux系统 initrd.img中init启动脚本分析
概述:这篇文章主体内容来源于网上转载.前面几篇文章倾向于制作initrd.img,这篇文章更倾向于initrd.img的运行过程:加载framebuff驱动 ide驱动和文件系统驱动,最后进入到真正的 ...
- ImageLoader初始化以及调用
1.首先在当前程序的Application中调用ImageLoader的初始化init()方法 [java] view plain copy private void initImageLoader( ...
- OSGi 系列(十三)之 Configuration Admin Service
OSGi 系列(十三)之 Configuration Admin Service OSGi 的 CM 就是 Configuration Admin Service,是用于管理 Bundle 属性.并在 ...
- [RSpec] LEVEL 2 CONFIGURATION & MATCHERS
Installing RSpec In this level we'll start by getting you setup on a regular Ruby project, then move ...
随机推荐
- MySQL UUID函数的详解(转)
MySQL UUID函数的详解 MySQL中可以有二类用于生成唯一值性质的工具:UUID()函数和自增序列,那么二者有何区别呢?我们就此对比下各自的特性及异同点: l 都可以实现生成唯一值的功能: ...
- SIFT 、Hog 、LBP 了解
SIFT.HOG.LBP,这三者都属于局部特征. 一.三者原理上的区别 1.SIFT:Scale-Invariant Feature Taransform,尺度不变特征变换. 尺度空间的极值检测:搜索 ...
- Lintcode---翻转二叉树
翻转一棵二叉树 您在真实的面试中是否遇到过这个题? Yes 样例 1 1 / \ / \ 2 3 => 3 2 / \ 4 4 思路:依旧采用递归的思路,判断特殊条件后,先交换根节点的左右孩子, ...
- MySQL主从配置的一些总结
有很多朋友做了mysql主从也有一段时间了,但是有时候也走了不少弯路,时间也浪费了不少,主要问题是没有查阅其他的主机配置的相关资料,而仅仅是看了配置文档,下面是作者对主从配置的一些总结. AD: 20 ...
- Linux下编译、使用静态库和动态库 自己测过的
每个程序实质上都会链接到一个或者多个的库.比如使用C函数的程序会链接到C运行时库,GUI程序会链接到窗口库等等.无论哪种情况,你都会要决定是链接到静态库(static libary)还是动态库(dyn ...
- vue2.0实现图片加载失败默认显示图片
<div class="bg"> <img :src="goods.phoneFloorAd.resUrl" :onerror="e ...
- 好工具 VHD
通过powershell 互转 Convert-VHD –Path F:\debian.vhdx –DestinationPath F:\debian.vhd 举个栗子 附加参考 Convert-VH ...
- 解决eclipse启动tomcat报错:Could not load the Tomcat server configuration at \Servers\Tomcat v6.0 Server at localhost-config. The Servers project is closed.
报错信息已经说的很清楚了:The Servers project is closed.如图 打开即可: 另外,如果你修改了Servers project的name(比如说把这里的Servers改成了X ...
- php的json校验json-schema
客户端和服务端的http信息传递,采用json几乎成了标配.json格式简单,易于处理,不过由于没有格式规定,无法校验. 好在php有json-schema模块,可以用来验证json是否符合规定的格式 ...
- lua工具库penlight--05日期和时间
创建和显示时间 Date类提过了简洁的使用date和time的方法.它依赖于os.date和os.time. Date对象可以通过table创建,如果os.date,同时提过了获取和设置date 成员 ...