Question

I can't get the bottom row below to center, specifically the columns with integers.

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Row"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:orientation="vertical"
    android:padding="10dip" >

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:id="@+id/player_profile"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="5dip" >

            <TextView
                android:id="@+id/player_number"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/player_name"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
        </TableRow>
    </TableLayout>

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="1" >

        <TableRow
            android:id="@+id/statistics_row"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="1dip"
            android:gravity="center_horizontal">

            <TextView
                android:id="@+id/statistic_points"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:layout_gravity="center_horizontal"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/statistic_rebounds"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:layout_gravity="center_horizontal"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/statistic_assists"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:layout_gravity="center_horizontal"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/statistic_steals"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:layout_gravity="center_horizontal"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/statistic_blocks"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:layout_gravity="center_horizontal"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/statistic_turnovers"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:layout_gravity="center_horizontal"
                android:layout_weight="1" />
        </TableRow>
    </TableLayout>

</LinearLayout>
Was it helpful?

Solution 2

It's not clear which row you're unhappy with, but realize that there are 2 different gravity attributes. layout_gravity positions the view that it's defined in, while gravity positions items within that view. For layouts, it positions the views within it; for views such as TextViews it positions the text within the view.

OTHER TIPS

try this..

 <?xml version="1.0" encoding="utf-8"?>

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TableRow
        android:id="@+id/player_profile"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dip" >

        <TextView
            android:id="@+id/player_number"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/player_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </TableRow>
</TableLayout>

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1" >

    <TableRow
        android:id="@+id/statistics_row"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="1dip"
        android:gravity="center_horizontal">

        <TextView
            android:id="@+id/statistic_points"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:gravity="center_horizontal"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/statistic_rebounds"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:textAlignment="center"
             android:gravity="center_horizontal"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/statistic_assists"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:gravity="center_horizontal"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/statistic_steals"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:textAlignment="center"
             android:gravity="center_horizontal"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/statistic_blocks"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:textAlignment="center"
             android:gravity="center_horizontal"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/statistic_turnovers"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:textAlignment="center"
             android:gravity="center_horizontal"
            android:layout_weight="1" />
    </TableRow>
</TableLayout>

Changed android:layout_gravity="center_horizontal" to android:gravity="center_horizontal"

Try that:

<?xml version="1.0" encoding="utf-8"?>

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TableRow
        android:id="@+id/player_profile"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:padding="5dip" >

        <TextView
            android:id="@+id/player_number"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/player_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </TableRow>
</TableLayout>

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1" >

    <TableRow
        android:id="@+id/statistics_row"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="1dip"
        android:gravity="center_horizontal">

        <TextView
            android:id="@+id/statistic_points"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:gravity="center"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/statistic_rebounds"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:gravity="center"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/statistic_assists"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:gravity="center"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/statistic_steals"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:gravity="center"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/statistic_blocks"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:gravity="center"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/statistic_turnovers"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:gravity="center"
            android:layout_weight="1" />
    </TableRow>
</TableLayout>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top