-1
To center the content, just use the attribute gravity
or the method setGravity
In XML:
<TextView
android:id="@+id/myId"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello World"
android:gravity="center" />
In Java
TextView text = findViewById(R.id.myTextView);
text.setGravity(View.Gravity.CENTER);
The difference between android:layout_gravity and android:Gravity, is that in the first, it will position the element, in case the Textview; Different from the second that will position the content of the element.
Have you tried
android:gravity="center"
?– Valdeir Psr
I was using layout_gravity. It worked! Tks
– Fabio Souza
Blz. I left a slightly more explanatory answer on the question.
– Valdeir Psr
Related: What’s the difference between Gravity and layout_gravity on Android?
– ramaral