已经尝试了一段时间,但没有任何效果。
我试图在相对布局内将线性布局垂直和水平居中。
重点是让两个 TextView 在相关布局内完美居中。
<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>
感谢任何帮助。
最佳答案
将属性 centerInParent
设置为 true 以在相对布局中将线性布局居中并将 gravity
设置为 center 在您的 TextView 线性布局
<LinearLayout
android:layout_width="350dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true"
android:gravity="center">
关于android - 如何在相对布局中垂直和水平居中线性布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34465773/