I have four TextView
items that I want to evenly spread in a horizontal line. This means that all the space in a line must be evenly occupied by the TextView
items. Like this:
Previously, I used LinearLayout for this. I had the weightSum as 4 and assigned a layout_weight of 1 to each TextView
item. However, this compromises on some functionality I want to implement in my app:
I want to put an EditText
item under each of the four TextView
items. The EditText
items visibility will be set to INVISIBLE first, and then at the touch of a button, the EditTexts will become visible and the visibility of the Textviews will be set to INVISIBLE. This is only possible if I use RelativeLayout
So how do I use RelativeLayout for the four TextView
items while evenly occupying all the space?
Relativelayout is more effective than Linearlayout. From here: 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.
relativelayout is deprecated now.
LinearLayout arranges elements side by side either horizontally or vertically. RelativeLayout helps you arrange your UI elements based on specific rules. You can specify rules like: align this to parent's left edge, place this to the left/right of this elements etc.
Simply put, you can't. That's why you were using a LinearLayout as the 4 TextViews container.
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