It can be programmatically:
textView.setGravity(Gravity.CENTER);
or by changing the property directly in the layout:
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Android"/>
- You can remove
android:paddingLeft="50dp"
already pushing your view to the right.
- I suggest you change
layout_width="match_parent"
by layout_width="wrap_content"
, since "match_parent"
is occupying the full width of the parent view.
If you want to center your view but on the whole screen horizontally and vertically, you can do it with a RelativeLayout
and use the properties
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
Example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/TituloApp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android"
android:textSize="55dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>