I'm assuming you're using XML layout.
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/**yourtextstring**"
/>
You can also use gravity center_vertical
or center_horizontal
according to your need.
and as @stealthcopter commented
in java: .setGravity(Gravity.CENTER);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…