How to clear ImageView correctly?

佐手、 提交于 2019-12-04 09:13:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!