Issue with RelativeLayout when View visibility is View.GONE

This answer does not solve your specific problem, but does solve a similar one, so hopefully this will help somebody.

I had a situation where my relative layout did not have the equivalent of your TextView1. So, in my situation, if TextView2 was GONE, then I wanted TextView3 to be aligned with the parent's top. I solved that by adding to TextView3 the attribute android:layout_alignWithParentIfMissing="true". See http://developer.android.com/resources/articles/layout-tricks-efficiency.html.

Unfortunately, I do not see a way to specify an alternate alignment anchor unless it is the parent.


You can use this tag:

android:layout_alignWithParentIfMissing="true"

From the docs:

If set to true, the parent will be used as the anchor when the anchor cannot be be found for layout_toLeftOf, layout_toRightOf, etc.


why not update the below attribute of TextView3 when you update the visibility of TextView2? (I assume you do this in code)

something like

TextView tv = (TextView) findViewById(R.id.textview3);
RelativeLayout.LayoutParams lp =
    (RelativeLayout.LayoutParams) tv.getLayoutParams();
lp.addRule(RelativeLayout.BELOW, R.id.textview1);
((TextView) view).setLayoutParams(lp);

You can place textview 2 and 3 in the LinearLayout and keep the linear layout below textview 1.