I have a TableLayout that contains only one row and one cell. I would like the content of my cell to be horizontally centered. I tried two approaches :
First method, I set the attribute android:gravity="center_horizontal" on the TableRow element and it works as expected :
    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TableRow android:gravity="center_horizontal">
            <Button
                android:id="@+id/MyButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"            
                android:text="@string/Hello" />
        </TableRow>
    </TableLayout>
Second method, I set the attribute android:layout_gravity="center_horizontal" directly on the cell content (the button here) but that doesn't centers the button :
<?xml version="1.0" encoding="utf-8"?>
        <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TableRow>
                <Button
                    android:id="@+id/MyButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"            
                    android:layout_gravity="center_horizontal"
                    android:text="@string/Hello" />
            </TableRow>
        </TableLayout>
Can someone explain me why the second approach doesn't work ?
Thank you
Riana
 
     
    