I've a RelativeLayout
thus:
<RelativeLayout> <TextView1/> <TextView2/> // <-- View.VISIBLE OR View.GONE <TextView3/> <TextView4/> </RelativeLayout>
Each TextView
is anchored below the previous TextView
with android:layout_below
.
The problem is that TextView2 may or may not be there (either View.VISIBLE
or View.GONE
); if it's View.VISIBLE
, then all is fine, but if it's View.GONE
, then TextView3 ends up being rendered on top of TextView1.
I've tried various ways to fix this, but each time am caught out by RelativeLayout
's 'you cannot reference an id before it's defined' rule.
I'm hoping that I'm missing something obvious here.
relativelayout is deprecated now.
View is a basic building block of UI (User Interface) in android. A view is a small rectangular box that responds to user inputs. Eg: EditText, Button, CheckBox, etc. ViewGroup is an invisible container of other views (child views) and other ViewGroup.
Relativelayout is more effective than Linearlayout. It is a common misconception that using the basic layout structures leads to the most efficient layouts. However, each widget and layout you add to your application requires initialization, layout, and drawing.
You can place textview 2 and 3 in the LinearLayout and keep the linear layout below textview 1.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With