ImageLoader使用
2024-08-22 20:37:04
最近琢磨的网上的这些开源框架,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
最新文章
- 使用 NuGet 下载最新的 Rafy 框架及文档
- c# .Net并行和多线程编程之Task学习记录!
- android view : 自定义
- admin site
- Jquery--防止冒泡
- Hadoop CLI MiniCluster
- MySQL中数据表的增操作
- 又一次认识HTML,CSS,Javascript 之node-webkit 初探
- CSS3+HTML5特效7 - 特殊的 Loading 效果
- 关于逆波兰式的c++实现
- wcf、web api、webservicer 之间的区别
- Java学习笔记--监视目录变化
- 加载进度圈,带遮罩层(jquery)
- 支持行单击、双击事件的GridView和DataList控件(译)
- 小白的python之路11/3总结
- SQL not exist out join
- python调用opencv库教程
- mysql 多列索引的生效规则,生成1000w数据的存储过程
- 微信小程序开发1-入门知识准备
- insert into与insert ignore以及replace into的区别
热门文章
- Codeforces 811 B. Vladik and Complicated Book
- 开源的图像滤镜库----for Android
- CF 915 D 拓扑排序
- codeforces Round #441 C Classroom Watch【枚举/注意起点】
- Cocos2dx-Lua UIScrollView 和 UITableView 对比
- luogu P1009 阶乘之和
- [BZOJ 3571] 画框
- [LOJ6436]神仙的游戏
- 【二分图】【最大匹配】【匈牙利算法】CODEVS 2776 寻找代表元
- python3开发进阶-Web框架的前奏