我重用ImageViews为我的显示,但在某些时候,我没有值把它。

那么如何在Android中清除ImageView呢?

我试过了:

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

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


当前回答

正如kwasi写的和golu编辑的,你可以使用透明,而不是白色:

文件可拉的/ transparent.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="@android:color/transparent"/>
</shape>

在活动、视图等内部:

view.setImageResource(R.drawable.transparent);

其他回答

对于ListView项目图像,您可以在列表适配器中设置ImageView.setVisibility(View.INVISIBLE)或ImageView.setImageBitmap(null),用于“无图像”情况。

这对我很有用。

emoji.setBackground(null);

这会在运行时崩溃。

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

如果你使用滑翔,你可以这样做。

Glide.with(yourImageView).clear(yourImageView)

我可以通过定义一个可绘制对象(类似于blank_white_shape.xml)来实现这一点:

<shape xmlns:android="http://schemas.android.com/apk/res/android"       
       android:shape="rectangle">
    <solid android:color="@android:color/white"/>
</shape>

当我想清除图像视图时,我只需调用

 imageView.setImage(R.drawable.blank_white_shape);

这对我来说非常有用!

editText.setText (" ");

imageView.setImageResource(0);