Pablo Pablo - 4 months ago 11
Android Question

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

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
?

Answer

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);