Frage

i have problem when set text gravity to center it's not appear in the middle ?!

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/AppBaseTheme"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

 <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="Large Text Large Text Large Text Large Text Large Text Large Text"
    android:layout_gravity="center"  
    android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>
War es hilfreich?

Lösung

If you want the whole TextView to be centered (which would then center the text) use android:layout_gravity

 <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="Large Text Large Text Large Text Large Text Large Text Large Text"
    android:layout_gravity="center"   // Here
    android:textAppearance="?android:attr/textAppearanceLarge" />

If this doesn't fix the problem then please post the full xml as you may have other Views/properties causing the issue.

Andere Tipps

use width to fill parent with the rest

android:layout_width="fill_parent"

I think it just look that way in IDE try to run your app and test. Happened to me as well but it turned out to be an IDE problem, so just check it out.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top