当前位置:网站首页>图片更新之后Glide加载依旧是原来的图片问题
图片更新之后Glide加载依旧是原来的图片问题
2022-08-01 05:05:00 【才疏学浅,努力修炼】
原因
Glide加载相同URL时由于缓存无法更新图片
解决方法
1,去掉缓存
如果是本地图片,可以采取取消缓存的方式,这样是比较简单的操作:
.skipMemoryCache(true) // 不使用内存缓存
.diskCacheStrategy(DiskCacheStrategy.NONE) // 不使用磁盘缓存
.into(imageView); 2,使用signature
无论本地图片网络图片,都可以使用另一个方法,就是使用Glide的方法.signature(Key signature),通过创建一个签名,然后在图片更新的时候,更改签名,达到重新加载的效果。该签名可以是个String,可以是图片更新的时间
Glide.with(getActivity())
.load(urlString)
.signature(new ObjectKey(DateTimeUtil.GetNowTime()))//也可以利用系统毫秒System.currentTimeMillis()
.into(portrait);注意:Glide 4.0中new StringSignature()类已经不在被支持,需改为new ObjectKey()
使用的工具类
public class DateTimeUtil {
public static String GetNowTime() {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
String str = formatter.format(curDate);
return str;
}
}边栏推荐
- ApiFile
- 零序电流继电器器JL-8C-12-2-2
- pytorch、tensorflow对比学习—计算图和微分机制
- The Principle Of Percona Toolkit Nibble Algorithm
- 力扣(LeetCode)212. 单词搜索 II(2022.07.31)
- pytroch、tensorflow对比学习—搭建模型范式(低阶、中阶、高阶API示例)
- MySQL-DML语言-数据库操作语言-insert-update-delete-truncate
- Immutable
- (2022牛客多校四)H-Wall Builder II(思维)
- y83. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (14)
猜你喜欢
随机推荐
typescript25 - type assertion
Pyspark Machine Learning: Vectors and Common Operations
在沈自所的半年总结
PMP 项目资源管理
SL-12/2过流继电器
LeetCode 387. 字符串中的第一个唯一字符
4D line-by-line analysis and implementation of Transformer, and German translation into English (3)
【堆】小红的数组
Asynchronous reading and writing of files
pytorch、tensorflow对比学习—功能组件(激活函数、模型层、损失函数)
(Codeforce 757) E. Bash Plays with Functions
pytroch、tensorflow对比学习—搭建模型范式(构建模型方法、训练模型范式)
高数 | 【重积分】线面积分880例题
pytorch、tensorflow对比学习—功能组件(优化器、评估指标、Module管理)
Selenium:元素等待
关于给Qt做一个软件初始化的进度条
JWL-11/2-99.9A电流继电器
Li Chi's work and life summary in July 2022
API设计笔记:pimpl技巧
(2022 Nioke Duo School IV) H-Wall Builder II (Thinking)









