I am using 4 textviews in a linear layout. I have assigned a weight of 3 to one textview and a weight of 1 to the remaining three textviews. I want to know how the screen real estate is calculated and allocated to each textview based on the assigned weight.
Asked
Active
Viewed 33 times
1
-
The sum of all weights is the total, and the individual weights are the fraction of that total, pretty straight forward really. – ci_ Jun 21 '15 at 11:17
-
1possible duplicate of [What does android:layout\_weight mean?](http://stackoverflow.com/questions/3995825/what-does-androidlayout-weight-mean) – ci_ Jun 21 '15 at 11:18
-
I agree, but what happens when one of the views is assigned a weight of 0 but is still present on the screen? How does that fraction work out? – Mudit Kakkar Jun 21 '15 at 14:13
-
Layout_weight distributes _extra_ space among views, you cannot use it to hide a view. It's all in the link. – ci_ Jun 21 '15 at 14:26
1 Answers
0
you can assign the linear layout with
android:weightSum="1"
and then this 1 represents 100% of the height/width (whatever you are using)
then in your textview if you use
android:layout_weight="0.2"
then you're giving the textview 20% of the layout space, and so on.

JozeRi
- 3,219
- 6
- 27
- 45