How do I center the text horizontally and vertically for a TextView in Android? How do I center the alignment of a TextView?
3 Answers
2
votes
0
votes
0
votes
It depends on how you have declared the height and width. If you used wrap_content, then the textview is just big enough in that direction to hold the text, so the gravity attribute will not apply. android:gravity affects the location of the text Within the space allocated for the textview. layout_xx attributes affect the location of the view within it's parent.
SO if you set the size of the textview, then use gravity to position the text within the textview area, if you used wrap_content, then use the layout_xx attributes to position the textview within it's parent