For example if I have a LinearLayout that occupies all the space horizontally, if I have two buttons, for each one occupy half the screen, how do I? GridLayout does not work in 2.2 right?
For example if I have a LinearLayout that occupies all the space horizontally, if I have two buttons, for each one occupy half the screen, how do I? GridLayout does not work in 2.2 right?
Use android:layout_weight
to proportionally define the space that each button occupies.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="BT1"
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="BT2"
</LinearLayout>
Since% w /%, in both cases, is set to 1, the two buttons will have the same length. For example if the first was set to 2 and the second to 1, then the first button would be twice as long as the second.
Use android:layout_alignParentLeft="true"
for one and android:layout_alignParentRight="true"
for another, setting android:layout_width="wrap_content"
for both
If you want to fill the button size horizontally, simply leave the default setting for Linear Layout. If you want to put a button next to the other you can use two different types of layout: Table or Relative. In the case of Table, you will create a column for each button. In the case of Relative, you will align one button according to the other ( link ) .