set TextView text horizontally vertically centered
There are 2 ways to set TextView text Center:
One: In the XML file settings: android:gravity= "center"
Two: In the program set: M_txttitle.setgravity (Gravity.center);
Note: The difference between android:gravity and Android:layout_gravity is that the former controls internal operations on the control, which is the entire control operation.
For example: android:gravity= "center" is centered on text in TextView
Android:layout_gravity= "Center" is centered on the TextView control throughout the layout
It is easy to understand that "layout" is the operation of the control over the entire layout.
Textview.setgravity (Gravity. CENTER);
The above is only the horizontal center of the text layout, to achieve vertical centering at the same time, you also need to implement the following layout:
Textview.setgravity (gravity.center_vertical);
However, after the above settings, the text is only implemented horizontally centered, not to achieve vertical center effect.
However, you can set the line wrapping to achieve the beautification effect.
Textview.settext ("\n\n\n No Product evaluation information ");
American and American pictures
Android Advanced (22) Set TextView text Horizontal Vertical Center