There are 2 ways to set the center of TextView text:
One: In the XML file settings: android:gravity= "center"
II: In the program set: Txttitle.setgravity (Gravity.center);
To set the center of a control:
Android:layout_gravity= "Center" is centered over the entire layout of the TextView control, or it can be invoked in its parent layout setting android:gravity= "Center"
The program is also the parent layout that needs to set its control, for example:
Relativelayout.layoutparams layoutparams=
New Relativelayout.layoutparams (RelativeLayout.LayoutParams.WRAP_ CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
Layoutparams.addrule (relativelayout.center_in_parent);
In fact, it's easy to understand that "layout" is the control's action on the entire layout
Note: Set to center vertically, which you can set in XML
Android:gravity= "Center_vertical"