I am trying to build something like a header. I tried using android:gravity="center"
and android:textAlignment="center"
on the TextView but it doesn't center the text. I don't know where the problem is.
<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:background="#008000" >
<TextView
android:id="@+id/HeaderTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
<!--android:textAlignment="center"
android:gravity="center"-->
android:text="@string/header"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFF"
android:textStyle="italic" />
</TableRow>
</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>
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