0

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>
Fawaz
  • 584
  • 1
  • 11
  • 24

3 Answers3

4

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.

codeMagic
  • 44,549
  • 13
  • 77
  • 93
  • it's doesn't fix the problem i have update my question – Fawaz Jan 13 '14 at 17:52
  • Are you sure that's the complete xml? Because if so, I see no reason for that text to be over to the right. Check in the GUI of your IDE and see where the `TextView` seems to be positioned. Also, try cleaning and rebuilding your project. – codeMagic Jan 13 '14 at 17:55
  • You have something else going on that we can't see. I just copied it into my editor and it showed correctly. Did you try cleaning the project as I suggested? What does `AppBaseTheme` do? – codeMagic Jan 13 '14 at 18:05
  • thank u i accidental removed android:theme="@style/AppBaseTheme" from in manifest ^_^ it's work now – Fawaz Jan 13 '14 at 18:21
0

use width to fill parent with the rest

android:layout_width="fill_parent"
Saqib
  • 1,120
  • 5
  • 22
  • 40
0

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.

vipul mittal
  • 17,343
  • 3
  • 41
  • 44