Reputation: 6583
<TextView
android:layout_height="30dp"
android:text="@string/list_title"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:textSize="@dimen/title_size"
android:textAlignment="center"
android:layout_alignParentTop="true"
android:background="@color/white"
android:id="@+id/list_title"
/>
Is the first element in a RelativeLayout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
But the text in the TextView will not center. I cannot understand why as all gravities and the textAlignment
property are set to "center".
What am I doing wrong?
Upvotes: 21
Views: 11021
Reputation: 71
if your textview is inside a constraintLayout then set its width to 0dp and then apply these constraints
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:textAlignment="center"
Upvotes: 0
Reputation: 3373
Try this:
<TextView
android:layout_height="30dp"
android:text="@string/list_title"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:textSize="@dimen/title_size"
android:textAlignment="center"
android:layout_alignParentTop="true"
android:background="@color/white"
android:id="@+id/list_title"
/>
Upvotes: 3