Glide的简单使用
1、在manifest中添加权限网络权限:
<uses-permission android:name="android.permission.INTERNET" />
没有添加网络权限就无法下载;
2、在build.gradle中添加glide依赖:
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'jp.wasabeef:glide-transformations:2.0.0'
第二个是对图片处理的
3、简单使用
Glide.with(this).load("http://content.52pk.com/files/100623/2230_102437_1_lit.jpg").into(iv);
Glide.with(this)
.load("http://imgstore04.cdn.sogou.com/app/a/100520024/877e990117d6a7ebc68f46c5e76fc47a")
.placeholder(R.mipmap.ic_launcher) //占位符
.error(R.mipmap.ic_launcher) //
.crossFade()
.fitCenter() //铺满长宽中较长的边
.centerCrop()
.thumbnail(0.1f) //缩略图,不过貌似没有效果
.bitmapTransform(new CropCircleTransformation(this)) //圆形显示图片
.bitmapTransform(new GrayscaleTransformation(this)) //灰色效果
.bitmapTransform(new RoundedCornersTransformation(this,30,0, RoundedCornersTransformation.CornerType.ALL)) //圆角
.diskCacheStrategy(DiskCacheStrategy.NONE) //禁止磁盘缓存
.crossFade(2000) //淡入
.skipMemoryCache(true) //是否跳过缓存
.into(iv); //图片显示位置的id
这些属性最好是一条条的试验。
Glide的load可以拿到多种资源,如url、文件路径等。
小技巧
清除缓存:
必须在UI 线程中调用
Glide.
get
(context).clearMemory();
清除磁盘缓存
必须在后台线程中调用
Glide.get(applicationContext).clearDiskCache();