如何在相对布局内垂直和水平居中线性布局

the*_*ole 2 android android-layout

一直试图这样做,但没有任何效果。

我试图垂直和水平居中相对布局内部的线性布局。

关键是要使两个文本视图完全位于相对布局的中心。

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    >

    <LinearLayout
        android:layout_width="350dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="test"
            android:textColor="#ff0fff"
            android:background="#ffffff"
            android:textSize="20dp"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="test"
            android:textColor="#ff0fff"
            android:background="#ffffff"
            android:textSize="20dp"
            />

    </LinearLayout>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏。

Iam*_*at8 5

将属性设置centerInParenttrue可使“线性布局”在“相对布局” gravity居中,并在“文本视图” 中居中LinearLayout

 <LinearLayout
    android:layout_width="350dp"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_centerInParent="true"
    android:gravity="center">
Run Code Online (Sandbox Code Playgroud)