<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#ff314859"android:paddingLeft="16dp"android:paddingRight="16dp"><TextViewandroid:id="@+id/txt_logo"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="your text here"android:textSize="30dp"android:gravity="center"/>
...other button or anything else...
</RelativeLayout>
<TextViewandroid:id="@+id/textView1"android:layout_width="fill_parent"android:layout_height="fill_parent"android:gravity="center_vertical|center_horizontal"android:text="Your Text goes here"/>
<TextViewandroid:id="@+id/textView1"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_centerInParent="true"android:text="Your Text goes here"/>
There are 2 ways to do this :
1. From Xmluse :<TextView.........android:gravity="center"/>
2. From Java classuse :
[textview].setGravity(Gravity.CENTER);
<TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Text In Center"android:layout_gravity="center"android:gravity="center"/>
相对布局
<TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:text="Text In Center"android:layout_centerInParent= true/>
<LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical">
<TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:textAlignment="center"android:gravity="center"android:textColor="#000"android:textSize="30sp"android:text="Welcome to Android" /></LinearLayout>
<TextViewandroid:text="This is my sample text."android:layout_width="match_parent"android:layout_height="35.7dp"android:id="@+id/textView2"android:layout_marginBottom="24.7dp"android:typeface="sans"android:textSize="20"android:gravity="center_vertical|center_horizontal" />