安卓使用glide加载图片

1,安卓加载图片

自己写的话是非常麻烦的,所以对于我们这种小白来说使用别人的开源库就是最好的选择:

glide

官网地址:https://muyangmin.github.io/glide-docs-cn/

2,引用

在build.gradle中添加如下代码,然后sync now

implementation ("com.github.bumptech.glide:glide:4.9.0") {
        exclude group: "com.android.support"
    }

3,使用

String imgUrl = "https://www.baidu.com/img/bd_logo1.png";
        Glide.with(this).load(imgUrl).into(codeImg);

实例代码:在adapter中使用

 Glide.with(holder.itemView)
                .load(user.getPreviewURL())
                .transition(withCrossFade())
                .placeholder(R.drawable.ic_launcher_background)
                .into(holder.imageView);

4,没有第四步了!就是这么简单!

你可能感兴趣的:(android)