I have the following code, how do I make it so that the 3 buttons are at the bottom?
You can use a RelativeLayout
and align it to the bottom with android:layout_alignParentBottom="true"
You need to ensure four things:
LinearLayout
has layout_height="match_parent"
LinearLayout
has layout_weight="1"
and layout_height="0dp"
TextView
has layout_weight="0"
LinearLayout: android:gravity="center|bottom"
Notice that fill_parent
does not mean "take up all available space". However, if you use layout_height="0dp"
with layout_weight="1"
, then a view will take up all available space (Can't get proper layout with "fill_parent").
Here is some code I quickly wrote up that uses two LinearLayouts in a similar fashion to your code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/db1_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/cow"
android:layout_weight="0"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="1" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="2" />
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="3" />
</LinearLayout>
</LinearLayout>
The result looks like similar to this:
You can bundle your Button(s) within a RelativeLayout even if your Parent Layout is Linear. Make Sure the outer most parent has android:layout_height attribute set to match_parent. And in that Button tag add 'android:alignParentBottom="True" '