Say you want a login screen with two text boxes and two buttons. And you want the buttons at the bottom of the screen. Here is how:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="10dip" > <EditText android:id="@+id/userName" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/userNameHint" android:singleLine="true" /> <EditText android:id="@+id/password" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dip" android:hint="@string/passwordHint" android:inputType="textPassword" android:singleLine="true" /> <!-- neat trick to push the stuff below all the way to bottom --> <View android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" /> <!-- divider --> <View android:layout_width="match_parent" android:layout_height="1dip" android:background="?android:attr/listDivider" /> <LinearLayout style="?android:attr/buttonBarStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:id="@+id/cancel" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:text="@android:string/cancel" /> <Button android:id="@+id/ok" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:enabled="false" android:text="@android:string/ok" /> </LinearLayout> </LinearLayout>
Instead of wrapping those two EditText's into another LinearLayout, we simply insert an empty View between text boxes and buttons with the weight. That should perform better.