国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

RelativeLayout布局

2019-11-09 14:39:17
字體:
來源:轉載
供稿:網(wǎng)友

RelativeLayout布局

相對布局(RelativeLayout)將子視圖元素以相對位置顯示。

居中顯示

layout_centerInParent:相對于父元素完全居中l(wèi)ayout_centerHorizontal:相對于父元素水平居中l(wèi)ayout_centerVertical:相對于父元素垂直居中
<?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">    <!-- 居中顯示,作為坐標元素 -->    <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:基準線與某元素的基準線對齊
<?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: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"/>    <!-- 基準線對齊 -->    <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>顯示如下
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 璧山县| 百色市| 永城市| 东光县| 措美县| 砚山县| 江安县| 黄大仙区| 上高县| 乌什县| 上高县| 六盘水市| 黎城县| 区。| 富阳市| 东兴市| 定西市| 五常市| 铜陵市| 新竹县| 乐亭县| 罗城| 来凤县| 资源县| 宜兴市| 关岭| 平谷区| 河北省| 始兴县| 逊克县| 内江市| 台中县| 高雄县| 延寿县| 张家港市| 巴林右旗| 张北县| 桑植县| 濉溪县| 林州市| 新营市|