How do I center text horizontally and vertically in a TextView on Android

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

How do I center the text horizontally and vertically in a TextView in Android, so that it appears exactly in the middle of the TextView?

Answers

I m assuming you re using XML layout.

<TextView  
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center"
    android:text="@string/**yourtextstring**"
/>

and as @stealthcopter commented in java: .setGravity(Gravity.CENTER);

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/432037/how-do-i-center-text-horizontally-and-vertically-in-a-textview-on-android

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils