You can set the gravity attribute (not layout_gravity ) to the center of the text. Make sure layout_width set to "fill_parent" . For example, in my_text_view.xml :
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"/>
And then you can use R.id.my_text_view as your resource identifier.
source share