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
source share