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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

RelativeLayout布局

2019-11-09 15:45:26
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

RelativeLayout布局

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

居中顯示

layout_centerInParent:相對(duì)于父元素完全居中l(wèi)ayout_centerHorizontal:相對(duì)于父元素水平居中l(wèi)ayout_centerVertical:相對(duì)于父元素垂直居中
<?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>顯示如下

相對(duì)于父控件的位置

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>顯示如下

相對(duì)于其他控件的位置

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>顯示如下

對(duì)齊方式

layout_alignTop:上邊與某元素的上邊對(duì)齊layout_alignBottom:下邊與某元素的下邊對(duì)齊layout_alignLeft:左邊與某元素的左邊對(duì)齊layout_alignRight:右邊與某元素的右邊對(duì)齊layout_alignBaseline:基準(zhǔn)線與某元素的基準(zhǔn)線對(duì)齊
<?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"/>    <!-- 左對(duì)齊 -->    <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"/>    <!-- 右對(duì)齊 -->    <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"/>    <!-- 上對(duì)齊 -->    <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"/>    <!-- 下對(duì)齊 -->    <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)線對(duì)齊 -->    <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ā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 修武县| 余干县| 仁怀市| 临汾市| 济源市| 汝城县| 金溪县| 南投县| 海南省| 屯留县| 晋中市| 万全县| 岫岩| 徐汇区| 阳谷县| 比如县| 武定县| 荆州市| 城市| 明星| 利津县| 淳化县| 阿克| 登封市| 阆中市| 静海县| 喀喇沁旗| 泸州市| 伽师县| 河池市| 同仁县| 车致| 卓尼县| 广州市| 内丘县| 平顶山市| 鄯善县| 沂南县| 甘谷县| 伊宁县| 清河县|