I wanted to know how to center a textview, since the title of the app is out of phase for me to the right and not in the center of the screen, thanks.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/TituloApp"
android:text="HOLA'"
android:paddingLeft="50dp"
android:textSize="55dp"
android:layout_marginTop="30dp"
/>
It can be programmatically:
or by changing the property directly on the layout:
android:paddingLeft="50dp"
this already by pushing your view to the right.layout_width="match_parent"
tolayout_width="wrap_content"
, since with"match_parent"
it it occupies the entire width of the parent view.If you want to center your view but across the entire screen horizontally and vertically, you can do this with a
RelativeLayout
and use the propertiesExample:
You can use
android:layout_centerHorizontal="true"
with alayout_width
ofwrap_content
and remove theandroid:paddingLeft="50dp"
Go to the layout where the component is
(Edittext)
, inXML
it you put this code to the component(android:textAlignment="center")
and then in the java activity you put the component(tv_bienvenida.setGravity(Gravity.CENTER);)
With this:
From code there are two ways, although both are valid:
either