您当前的位置: 首页 >  ide

蓝不蓝编程

暂无认证

  • 0浏览

    0关注

    706博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Android集成Glide样例(回调,圆角roundCorner,居中裁剪centerCrop,gif)

蓝不蓝编程 发布时间:2018-10-23 19:26:58 ,浏览量:0

最近一次更新: 2019.08.08

背景

Glide是当前非常流程的图片加载框架,功能强大而且非常稳定。

集成指导 最简集成方式

1.dependencies中增加依赖

implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
  1. Manifest文件中增加权限


  1. 使用
  • 样例1:
String url = "https://p3a.pstatp.com/weili/l/79054173089494582.jpg";
Context context = this;
Glide.with(context)
       .load(url)
       .into(imageView);
  • 样例2(带回调,使用样例:加载完图片再显示出图片控件):
String url = "https://p3a.pstatp.com/weili/l/79054173089494582.jpg";
Context context = this;
Glide.with(context)
       .load(url)
       .listener(new RequestListener() {
           @Override
           public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
               Toast.makeText(context, "加载失败!", Toast.LENGTH_SHORT).show();
               return false;
           }

           @Override
           public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
               Toast.makeText(context, "加载成功.", Toast.LENGTH_SHORT).show();
               return false;
           }
       })
       .into(imageView);
  • 样例3:显示圆角及居中裁剪
//居中裁剪
private fun centerCropImg() {
    Glide.with(this)
            .load(url)
            .centerCrop()
            .into(roundCornerIv)
}

//圆角
private fun roundCornerImg() {
    Glide.with(this)
            .load(url)
            .transform(RoundedCorners(20))
            .into(centerCropIv)
}

//居中裁剪+圆角
private fun centerCropAndRoundCornerImg() {
    Glide.with(this)
            .load(url)
            .transform(MultiTransformation(CenterCrop(), RoundedCorners(20)))
            .into(roundCornerAndCenterCropIv)
}

效果图:

  • 样例4:gif动图
val url = "https://c-ssl.duitang.com/uploads/item/201703/17/20170317135641_dFL5w.gif"
Glide.with(this)
        .load(url)
        .into(imageView)

#源代码: https://gitee.com/cxyzy1/glideDemo.git

附录

https://blog.csdn.net/guolin_blog/article/details/53759439?utm_source=tuicool&utm_medium=referral https://blog.csdn.net/mingyunxiaohai/article/details/79760784 https://www.jianshu.com/p/90b4749e59d2

安卓开发技术分享: https://blog.csdn.net/yinxing2008/article/details/84555061

关注
打赏
1639405877
查看更多评论
立即登录/注册

微信扫码登录

0.0398s