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

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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值