要在RelativeLayout中居中显示控件,可以使用以下方法:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="居中显示的文本" android:layout_centerInParent="true" /> </RelativeLayout> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="水平垂直居中显示的文本" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /> </RelativeLayout> 通过以上方法,可以在RelativeLayout中实现控件的居中显示。