I have this layout:
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/darker_gray"
android:orientation="horizontal" >
<TextView
android:id="@+id/mon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="M\nO\nN" />
<CheckBox
android:id="@+id/cbmon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10" />
<TimePicker
android:id="@+id/timePicker1mon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
<TimePicker
android:id="@+id/timePicker2mon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/white"
android:orientation="horizontal" >
<TextView
android:id="@+id/mon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="T\nU\nE" />
<CheckBox
android:id="@+id/cbtue"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10" />
<TimePicker
android:id="@+id/timePicker1tue"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
<TimePicker
android:id="@+id/timePicker2tues"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/darker_gray"
android:orientation="horizontal" >
<TextView
android:id="@+id/mon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="W\nE\nD" />
<CheckBox
android:id="@+id/cbwed"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10" />
<TimePicker
android:id="@+id/timePicker1wed"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
<TimePicker
android:id="@+id/timePicker2wed"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/white"
android:orientation="horizontal" >
<TextView
android:id="@+id/mon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="T\nH\nU" />
<CheckBox
android:id="@+id/cbthu"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10" />
<TimePicker
android:id="@+id/timePicker1thu"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
<TimePicker
android:id="@+id/timePicker2thu"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/darker_gray"
android:orientation="horizontal" >
<TextView
android:id="@+id/mon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="F\nR\nI" />
<CheckBox
android:id="@+id/cbfri"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10" />
<TimePicker
android:id="@+id/timePicker1fri"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
<TimePicker
android:id="@+id/timePicker2fri"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/white"
android:orientation="horizontal" >
<TextView
android:id="@+id/mon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="S\nA\nT" />
<CheckBox
android:id="@+id/cbsat"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10" />
<TimePicker
android:id="@+id/timePicker1sat"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
<TimePicker
android:id="@+id/timePicker2sat"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/darker_gray"
android:orientation="horizontal" >
<TextView
android:id="@+id/mon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10"
android:text="S\nU\nN" />
<CheckBox
android:id="@+id/cbsun"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="10" />
<TimePicker
android:id="@+id/timePicker1sun"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
<TimePicker
android:id="@+id/timePicker2sun"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="40" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/white"
android:orientation="horizontal" >
<Button
android:id="@+id/okbutton"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:text="SET"
android:gravity="center"
android:textSize="50sp" />
</LinearLayout>
WHY do I get this result??? I would expect the button "SET" to be centered horizontally:
Set button's parent linear layout gravity to center
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/white"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/okbutton"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:text="SET"
android:gravity="center"
android:textSize="50sp" />
</LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With