Wednesday, September 21, 2011

Create proportionate size layout in android

Tip: To create a proportionate size layout on the screen, create a container view group object with the layout_width and layout_height attributes set to fill_parent; assign the children height or width to 0 (zero); then assign relative weight values to each child, depending on what proportion of the screen each should have.

This is the tip from android developers website, I don’t know about you, but it took me five or six time to understand what it means. An example is better than thousand words.

As you can see, I have a ListView and two buttons, I want list view to take 60% of width and 20% each for the buttons.

Layout definition in xml, Take a look at these attributes, android:layout_width android:layout_weight