Android: center text horizontally and vertically in a TextView

By default, text appears on the top left of a TextView. To center it vertically, you need to use the gravity property : In your xml layout file, add the following property : android:gravity=”center_vertical” To center the text vertically and horizontally : Use the following property : android:gravity=”center” To do it programmatically, use the following syntax : …