封装图片加载,任意切换图片库
统一管理图片加载库,随意切换图片加载框架
- Fresco
- Picasso
- Glide
- Universal-ImageLoader
- Volley
封装
- 多个图片加载库切换
- 图片加载进度回调
- 自定义配置(如占位图片、错误占位图片、缓存目录、大小等)
- 清除缓存
使用
独立依赖库
1
2
3
4
5implementation 'com.excellence:imageloader:_latestVersion'
// 下面图库三选一,减小安装包大小
implementation 'com.excellence:imageloader-fresco:_latestVersion'
implementation 'com.excellence:imageloader-picasso:_latestVersion'
implementation 'com.excellence:imageloader-glide:_latestVersion'权限
1
2
3
4<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>API
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78// 初始化,不同的加载器,有部分独立的方法
// 可以自定义实现ImageLoader接口,创建新的图库加载器
ImageLoaderOptions options = new ImageLoaderOptions.Builder().isLogEnable(true).isCache(false).build();
mImageLoader = new FrescoImageLoader(this, options);
mImageLoader = new PicassoImageLoader(this, options);
mImageLoader = new GlideImageLoader(this, options);
// 统一的接口
public interface ImageLoader
{
/**
* 加载资源图片
*
* @param view
* @param resId
*/
void loadImage( ImageView view, int resId);
void loadImage( ImageView view, int resId, IListener listener);
/**
* 加载资源图片,占位图片,错误图片
*
* @param view
* @param resId
* @param placeholderResId
* @param errorResId
*/
void loadImage( ImageView view, int resId, int placeholderResId, int errorResId);
void loadImage( ImageView view, int resId, int placeholderResId, int errorResId, IListener listener);
/**
* 加载本地图片
*
* @param view
* @param file
*/
void loadImage( ImageView view, File file);
void loadImage( ImageView view, File file, IListener listener);
/**
* 加载本地图片,占位图片,错误图片
*
* @param view
* @param file
* @param placeholderResId
* @param errorResId
*/
void loadImage( ImageView view, File file, int placeholderResId, int errorResId);
void loadImage( ImageView view, File file, int placeholderResId, int errorResId, IListener listener);
/**
* 加载网络图片
*
* @param view
* @param url
*/
void loadImage( ImageView view, String url);
void loadImage( ImageView view, String url, IListener listener);
/**
* 加载网络图片,占位图片,错误图片
*
* @param view
* @param url
* @param placeholderResId
* @param errorResId
*/
void loadImage( ImageView view, String url, int placeholderResId, int errorResId);
void loadImage( ImageView view, String url, int placeholderResId, int errorResId, IListener listener);
void clearCache();
}
Fresco
1 | implementation 'com.facebook.fresco:fresco:1.9.0' |
1 | Uri uri = Uri.parse("https://raw.githubusercontent.com/facebook/fresco/gh-pages/static/logo.png"); |
Picasso
1 | implementation 'com.squareup.picasso:picasso:2.71828' |
1 | Picasso.get() |
缓存路径:data/data/your package name/cache/picasso-cache/(默认路径)
Glide
1 | implementation 'com.github.bumptech.glide:glide:4.8.0' |
1 | Glide.with(getContext()) |
Universal-ImageLoader
Volley
版本更新
版本 | 描述 |
---|---|
1.0.0 | 封装Fresco、Picasso、Glide图库,简单加载图片 2018-10-11 |