Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to weightSum in RelativeLayout?

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:

Evenly spaced TextViews

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?

like image 327
Akshay Damle Avatar asked Jan 15 '14 17:01

Akshay Damle


People also ask

Which is better LinearLayout or RelativeLayout?

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.

Is RelativeLayout deprecated?

relativelayout is deprecated now.

What is the difference between RelativeLayout and LinearLayout?

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.


1 Answers

Simply put, you can't. That's why you were using a LinearLayout as the 4 TextViews container.

like image 197
Phantômaxx Avatar answered Oct 14 '22 11:10

Phantômaxx