0

I have an app where there's a dialog which contains conditions with a button below named as "Got it". My problem is that I want the text in the TextView to be in proper alignment line by line.

code:-

 <TextView
    android:id="@+id/HeaderText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/mainImage"
    android:layout_centerInParent="true"
    android:fontFamily="sans-serif-light"
    android:gravity="center_vertical"
    android:padding="10dp"
    android:layout_marginLeft="10sp"
    android:layout_marginRight="10sp"
    android:text="*kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
    android:textColor="#000"
    android:textSize="16sp"/>

Image:

Image

ebarrenechea
  • 3,775
  • 1
  • 31
  • 37
Satish
  • 171
  • 1
  • 1
  • 8
  • Possible duplicate of [How do I center text horizontally and vertically in a TextView on Android?](http://stackoverflow.com/questions/432037/how-do-i-center-text-horizontally-and-vertically-in-a-textview-on-android) – Ahmad Aghazadeh Sep 09 '16 at 06:03
  • You can use `android:gravity="center"` or ` android:gravity="center_vertical|center_horizontal"`' – Ahmad Aghazadeh Sep 09 '16 at 06:04
  • see i want kkkk below kkkkkk not below * – Satish Sep 09 '16 at 06:19
  • A TextView doesn't know the difference between `*` and `k`. It only cares that all characters are properly displayed according to the view configuration. It will always put the 1st character on a new line right below the first character on the previous line, hence `k` will always be below `*` in this case. – ebarrenechea Sep 11 '16 at 14:16

2 Answers2

0

Try below code......

<TextView
        android:id="@+id/HeaderText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/mainImage"
        android:layout_centerInParent="true"
        android:fontFamily="sans-serif-light"
        android:gravity="center_vertical"
        android:text="*kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"
        android:textColor="#000"
        android:textSize="16sp" />
Android Geek
  • 8,956
  • 2
  • 21
  • 35
0

You can try a combination as :

android:gravity="left|center"