最近琢磨的网上的这些开源框架,imageLoader确实很好用,基本用法不记录了,参考网上的一些代码写了个ImageLoaderManager

 /**
* Created by Lee on 2016/2/22.
*/
public class ImageLoaderManager {
public static DisplayImageOptions.Builder IMAGE_OPTION_DEFAULT = new DisplayImageOptions.Builder()
.cacheInMemory(true).cacheOnDisk(true).displayer(new SimpleBitmapDisplayer())
.resetViewBeforeLoading(true).considerExifParams(true).bitmapConfig(Bitmap.Config.RGB_565); public static DisplayImageOptions IMAGE_OPTION_DEFAULT_PIC = IMAGE_OPTION_DEFAULT
.showImageForEmptyUri(R.drawable.ic_launcher)
.showImageOnFail(R.drawable.ic_launcher)
.showImageOnLoading(R.drawable.ic_launcher)
.build(); public static void init(Context context){
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).
memoryCacheExtraOptions(480, 800). //max width, max height
threadPoolSize(3). //线程池内加载的数量
threadPriority(Thread.NORM_PRIORITY).denyCacheImageMultipleSizesInMemory().
memoryCache(new LruMemoryCache(2 * 1024 * 1024)). //you can pass your own memory cache implementation
memoryCacheSize(2 * 1024 * 1024).
diskCacheSize(50 * 1024 * 1024)
.diskCacheFileNameGenerator(new Md5FileNameGenerator())//将保存的时候的URI名称用MD5 加密
.tasksProcessingOrder(QueueProcessingType.LIFO)
.diskCacheFileCount(100) //缓存的文件数量
.diskCache(new UnlimitedDiskCache(StorageUtils.getCacheDirectory(context)))//自定义缓存路径
.defaultDisplayImageOptions(IMAGE_OPTION_DEFAULT.build())
.imageDownloader(new BaseImageDownloader(context, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超时时间
.build();//开始构建
ImageLoader.getInstance().init(config);//全局初始化此配置
}
}

我们需要在全局初始化这个ImageLoader,所以在application类中我们需要init

 public class MyApplication extends Application{

     private static MyApplication instance;

     public static MyApplication getInstance(){
return instance;
} @Override
public void onCreate() {
super.onCreate(); instance = this;
initImageLoader();
} private static void initImageLoader(){
ImageLoaderManager.init(instance.getApplicationContext());
}

调用时只需要一行代码

    public void setImage(String url){
ImageLoader.getInstance().displayImage(url, image, ImageLoaderManager.IMAGE_OPTION_DEFAULT_PIC);
}

image为imageview

最新文章

  1. 使用 NuGet 下载最新的 Rafy 框架及文档
  2. c# .Net并行和多线程编程之Task学习记录!
  3. android view : 自定义
  4. admin site
  5. Jquery--防止冒泡
  6. Hadoop CLI MiniCluster
  7. MySQL中数据表的增操作
  8. 又一次认识HTML,CSS,Javascript 之node-webkit 初探
  9. CSS3+HTML5特效7 - 特殊的 Loading 效果
  10. 关于逆波兰式的c++实现
  11. wcf、web api、webservicer 之间的区别
  12. Java学习笔记--监视目录变化
  13. 加载进度圈,带遮罩层(jquery)
  14. 支持行单击、双击事件的GridView和DataList控件(译)
  15. 小白的python之路11/3总结
  16. SQL not exist out join
  17. python调用opencv库教程
  18. mysql 多列索引的生效规则,生成1000w数据的存储过程
  19. 微信小程序开发1-入门知识准备
  20. insert into与insert ignore以及replace into的区别

热门文章

  1. Codeforces 811 B. Vladik and Complicated Book
  2. 开源的图像滤镜库----for Android
  3. CF 915 D 拓扑排序
  4. codeforces Round #441 C Classroom Watch【枚举/注意起点】
  5. Cocos2dx-Lua UIScrollView 和 UITableView 对比
  6. luogu P1009 阶乘之和
  7. [BZOJ 3571] 画框
  8. [LOJ6436]神仙的游戏
  9. 【二分图】【最大匹配】【匈牙利算法】CODEVS 2776 寻找代表元
  10. python3开发进阶-Web框架的前奏