如何清除 Android 中的 ImageView? [英] How to clear an ImageView in Android?

查看:33
本文介绍了如何清除 Android 中的 ImageView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 ImageView 重用于我的显示器,但在某些时候我没有值可以放置它.

I am reusing ImageViews for my displays, but at some point I don't have values to put it.

那么如何在Android中清除ImageView?

So how to clear an ImageView in Android?

我试过了:

mPhotoView.invalidate();
mPhotoView.setImageBitmap(null);

他们都没有清除视图,它仍然显示以前的图像.

None of them have cleared the view, it still shows previous image.

推荐答案

我曾经使用 dennis.sheppard 解决方案:

I used to do it with the dennis.sheppard solution:

viewToUse.setImageResource(0);

它可以工作,但没有记录,所以不清楚它是否会影响视图中的其他内容(您可以查看 ImageView 代码 如果你喜欢,我没有).

it works but it is not documented so it isn't really clear if it effects something else in the view (you can check the ImageView code if you like, i didn't).

我认为最好的解决方案是:

I think the best solution is:

viewToUse.setImageResource(android.R.color.transparent);

我最喜欢这个解决方案,因为在恢复状态时没有任何棘手的事情,而且它在做什么也很清楚.

I like this solution the most cause there isn't anything tricky in reverting the state and it's also clear what it is doing.

这篇关于如何清除 Android 中的 ImageView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆