您的位置:首页 > 其它

图片加载框架Glide的简单使用

2017-06-30 10:25 369 查看

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);


4、设置属性
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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  框架 glide