Mbio

Technology & business for life & change

Posts Tagged ‘weight

Android, LinearLayout Distribution Explained (weight and sizes)

with 16 comments

So this is one of the most bothering issues I have faced during my experience in Android. Besides it has been difficult to find a solution through the internet and in Android Developers it is not as detailed as expected so I feel that this post shall give you a hand to all of you who are still struggling.

I will focus on the main problem as I am sure all of you are familiar with the basic theory.

The problem: How in the world can I control the distribution of the elements in a LinearLayout? Yes, I have seen some examples using widths and heights of  0 dip and weights but, what does that mean exactly?

Weight: This has been the way of the Android team to achieve proportional distribution of elements within a LinearLayout. Others did that by using the classic percentages which might be more straightforward. Anyway, the idea here is the same with the only difference that weights are factors and percentages are…percentages. Let’s use a simple example:

Say you have a horizontal LinearLayout and you need to put 2 buttons and an image inside so that the buttons take the half of the space:

Read the rest of this entry »

Written by joseluisugia

19, January.2012 at 14:32