There are 2 ways to set the TextView text to center:
1: Settings in xml file: Android:gravity="center"
2: Set in the program: ();
Set the control to center:
android:layout_gravity="center" is to center the textview control in the entire layout, and you can also call android:gravity="center" in its parent layout.
The parent layout of the control it is also required in the program, for example:
layoutParams= new (.WRAP_CONTENT, .WRAP_CONTENT); (RelativeLayout.CENTER_IN_PARENT); (layoutParams);
In fact, it is easy to understand. The appearance of "layout" is the operation of the control on the entire layout.
Note: Set vertical centering, you can set it in XML
Android:gravity="center_vertical"