<?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"> <!-- 居中顯示 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="centerInParent" android:background="#ffa6a5aa"/> <!-- 水平居中 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="centerHorizontal" android:background="#ffa6a5aa"/> <!-- 垂直居中 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="centerVertical" android:background="#ffa6a5aa"/></RelativeLayout>顯示如下相對于父控件的位置
layout_alignParentTop:父元素的上邊layout_alignParentBottom:父元素的下邊layout_alignParentLeft:父元素的左邊layout_alignParentRight:父元素的右邊<?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"> <!-- 左上角顯示 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="Left|Top" android:background="#ffa6a5aa"/> <!-- 右上角顯示 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="Right|Top" android:background="#ffa6a5aa"/> <!-- 左下角顯示 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true" android:text="Left|Bottom" android:background="#ffa6a5aa"/> <!-- 右下角顯示 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:text="Right|Bottom" android:background="#ffa6a5aa"/></RelativeLayout>顯示如下相對于其他控件的位置
layout_above:某元素的上邊layout_below:某元素的下邊layout_toRightOf:某元素的右邊layout_toLeftOf:某元素的左邊<?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"> <!-- 居中顯示,作為坐標(biāo)元素 --> <TextView android:id="@+id/tv_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="center" android:textSize="32dp" android:background="#ffffcc00"/> <!-- 顯示在左上角 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/tv_center" android:layout_above="@id/tv_center" android:text="above|toLeftOf" android:background="#ffa6a5aa"/> <!-- 顯示在右下角 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/tv_center" android:layout_below="@id/tv_center" android:text="below|toRightOf" android:background="#ffa6a5aa"/></RelativeLayout>顯示如下對齊方式
layout_alignTop:上邊與某元素的上邊對齊layout_alignBottom:下邊與某元素的下邊對齊layout_alignLeft:左邊與某元素的左邊對齊layout_alignRight:右邊與某元素的右邊對齊layout_alignBaseline:基準(zhǔn)線與某元素的基準(zhǔn)線對齊<?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"> <!-- 居中顯示,作為坐標(biāo)元素 --> <TextView android:id="@+id/tv_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="center" android:textSize="32dp" android:background="#ffffcc00"/> <!-- 左對齊 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@id/tv_center" android:layout_above="@id/tv_center" android:text="alignLeft" android:background="#ffa6a5aa"/> <!-- 右對齊 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@id/tv_center" android:layout_below="@id/tv_center" android:text="alignRight" android:background="#ffa6a5aa"/> <!-- 上對齊 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/tv_center" android:layout_toLeftOf="@id/tv_center" android:text="alignTop" android:background="#ffa6a5aa"/> <!-- 下對齊 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@id/tv_center" android:layout_toRightOf="@id/tv_center" android:text="alignBottom" android:background="#ffa6a5aa"/> <!-- 基準(zhǔn)線對齊 --> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@id/tv_center" android:text="alignBaseline" android:layout_toLeftOf="@id/tv_center" android:background="#ffa6a5aa"/></RelativeLayout>顯示如下
新聞熱點(diǎn)
疑難解答