There are two different scenarios, in two different layout modes: LinearLayout andRelative
Layout
1. LinearLayout
a). android:layout_gravity= "Center_horizontal" means that the layout is centered horizontally in the parent layout, at which point the parent layout must have the android:orientation= "vertical" property;
b). android:layout_gravity= "center_vertical" means that the layout is centered vertically in the parent layout, at which point the parent layout must be set to android:orientation= "Horizontal" Property (the default is the property), and the height of its parent layout should be set to Android:layout_height= "Fill_parent" property;
2. Relativelayout
Property value is True or False
a). android:layout_centerhrizontal controls are centered horizontally in the parent layout
b). android:layout_centervertical controls are centered vertically in the parent layout
c). Android:layout_centerinparent control is completely centered relative to the parent element
To be clear here, do you want the content in the control to be centered horizontally, or is it centered horizontally in the parent control,
a). Let the content inside the TextView be centered horizontally: android:gravity= "Center_horizontal"
b). Let the TextView control be centered horizontally in its parent layout android:layout_gravity= "Center_horizontal"
How to center the control in Android layout