Android How to remove ImageView from RelativeLayout

I'm trying to figure out what is the correct way to remove ImageView from RelativeLayout? I tried

relativeLayout.removeView(someImageView) 

but it causes some problems on some phones. See another post here for stacktrace. Removing ImageView crashes on some phones

I really don't want to make a decision where you just make it disappear because it is basically a memory leak in ImageView?

 someImageView.setVisibility(View.GONE); 

Any other ideas would be greatly appreciated.

+4
source share
1 answer

If you remove a view from a relative layout, you must reset the relative layout options for all other views, which depend on the view you are deleting. Otherwise, these other views will refer to your remote view and throw NPE.

Consider using a different root layout (e.g. LinearLayout ) if you want to achieve this without using View.GONE

+2
source

Source: https://habr.com/ru/post/1436818/


All Articles