问题
For example, in my Activity I have such code (I skip the initialization of variables):
ImageView iview; //some ImageView
Bitmap b; //some Bitmap
iview.setImageBitmap(b);
Question is - how to clear iview resources correctly (with or without destroying view) ? Would ImageView free it's resources (used in native code) after b.recycle()?
I suppose, that ImageView doesn't just free it resources after Activity onStop (or onDestroy).
回答1:
imgview.setImageResource(0);
or
imgview.setImageDrawable(null);
回答2:
no you need to unbindDrawables, you can do it by setting iview.setImageDrawable(null);
回答3:
You can use frequently it works:
imageView.setImageResource(0);
回答4:
viewToUse.setImageResource(android.R.color.transparent);
- I think using setImageResource with a color identifier will give you crashing issues on Android 2.2.1, make sure to test it.
回答5:
if nothing is working for you try setting the background color of view to layout color.if my layout color is white u can do like this:
edit_countflag.setBackgroundColor(Color.parseColor("#ffffff"));
//then set the image
edit_countflag.setImageResource(R.drawable.flag_id);
来源:https://stackoverflow.com/questions/9498094/how-to-clear-imageview-correctly