Picasso
使用方法
Picasso.with(上下文).load(图片url).placeholder(加载成功前的默认图片)
.error(加载错误时的图片).into(imageview);
修改picasso图片缓存路径
由于picasso是单例模式,只需在Application中onCreate方法中设置即可
/**
* 设置图片缓存路径和配置
*/
File file = new File(Constant.CACHE_PATH_EXTERNAL);//图片路径
if (!file.exists()) {
file.mkdirs();
}
//设置图片内存缓存大小为运行时内存的八分之一
long l = Runtime.getRuntime().maxMemory();
OkHttpClient client = new OkHttpClient();
client.setCache(new Cache(file, l / 8));
Picasso picasso = new Picasso.Builder(this)
.memoryCache(new LruCache((int) (l/8)))
.downloader(new OkHttpDownloader(client))//使用okhttp下载图片
.defaultBitmapConfig(Bitmap.Config.RGB_565)
.loggingEnabled(Constant.LOGGING_OPEN)//picasso log日志
.build();
Picasso.setSingletonInstance(picasso);