如何刷新ImageView的内容

Mul*_*ard 3 android

我有一个屏幕,ImageView其中包含实际的个人资料图片.我可以通过用相机拍照或从SD卡中挑选照片来编辑该个人资料照片.我将新选择的个人资料图片存储在与旧的相同的路径下(我覆盖它),这是我猜的逻辑.

但是,当我为我设置一个新的个人资料图片时,ImageView它不会刷新.我必须重新启动应用程序以查看更改.

this.imageView.invalidate();
Run Code Online (Sandbox Code Playgroud)

当我浏览谷歌时所有人都告诉我要做的事情但是没有,这是行不通的!那么我如何强制我的imageview加载新的个人资料图片?

我在ImageViewPicasso的帮助下将图像加载到了:

Picasso picasso = Picasso.with(context);

if(reload) {
    picasso.invalidate(new File(fileName));
}

RequestCreator requestCreator = picasso.load(new File(fileName));
requestCreator.into(imageView);
Run Code Online (Sandbox Code Playgroud)

Xav*_*ler 7

Picasso缓存加载的图像以加速加载过程.这意味着如果您尝试重新加载相同的图片,则会加载缓存版本,并且不会File从磁盘读取更改.

您需要告诉Picasso图片已更改,并且需要通过使缓存无效来从磁盘重新加载图片.你这样做的方式是这样的:

File file = new File(fileName);
Picasso picasso = Picasso.with(context);
picasso.invalidate(file);
picasso.load(file).into(imageView);
Run Code Online (Sandbox Code Playgroud)