android:layout_centerHorizontal="true"
android:layout_centerHorizontal="true"
there is also
android:layout_centerInParent="true"
Full list for RelativeLayout attributes is here
Also you can tell your TextView to fill_parent and then set gravity=center on it. So it'll center actual text within textView.
As a more general answer to this question, layout_gravity does not work with the subviews of a RelativeLayout. It is for use with a LinearLayout or FrameLayout. However, the subviews of a RelativeLayout can still use gravity as usual because this is just how a view arranges its own content.
See the comparison in the following image. The green and blue views are TextViews inside of a RelativeLayout.

The gravity works but layout_gravity doesn't. See my fuller answer for more details.
See also
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With