app的gradle添加依赖:
compile 'com.github.bumptech.glide:glide:3.7.0'
加载网络图片:
Glide.with(this)
.load("图片的Url")
.signature(new StringSignature("你的标记字符串"))//设置签名
.error(getResources().getDrawable(R.mipmap.img))//加载失败后的默认图片
.into(imageView);
signature(new StringSignature("你的标记字符串"))
这是在设置签名,Glide自带了缓存机制,当Url对应的图片改变了,但Url没有改变,图片是不会更新的,所以设置签名后,当签名值改变了图片就会更新
加载图片成功和失败后的结果处理函数:
Glide.with(this).load("图片url")
.error(getResources().getDrawable(R.mipmap.img))//加载失败后的默认图片
.into(new GlideDrawableImageViewTarget(imageView) {
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
//图片加载失败后,你想以此为基础进行的一些处理操作可以写在这里
}
@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) {
super.onResourceReady(resource, animation);
//图片加载成功后,你想以此为基础进行的一些处理操作可以写在这里
}
});