继承GlideUrl重写getCacheKey()
package com.raysharp.common.glide;
import com.bumptech.glide.load.model.GlideUrl;
public class SelfGlideUrl extends GlideUrl {
public SelfGlideUrl(String url) {
super(url);
}
@Override
public String getCacheKey() {
// 这里根据需求构建缓存key
String cacheKey = super.getCacheKey();
return cacheKey;
}
}
使用
Glide.with(this)
.load(new SelfGlideUrl("http://a1.att.hudong.com/54/80/01000000000000119088089057754.jpg"))
.apply(new RequestOptions()
.error(R.drawable.ic_thumbnail)
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE))
.into(mDataBinding.ivTest);

本文介绍了如何在Android中针对Glide图片加载库进行自定义缓存key的设置,通过继承GlideUrl并重写getCacheKey()方法,实现更灵活的缓存控制。
1053

被折叠的 条评论
为什么被折叠?



