Center a TextView in a TableRow in a TableLayout

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:background="#008000" >

    <TextView
        android:id="@+id/HeaderTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="header"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#FFF"
        android:textStyle="italic" />
</TableRow>


give android:gravity="center" to TableRow.


Set gravity to table row

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

           <TableRow 
                android:gravity="center_horizontal"/>
</TableLayout>

Tags:

Xml

Android