国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 河北区| 永和县| 葫芦岛市| 洞头县| 雅江县| 化州市| 基隆市| 麻城市| 东辽县| 商水县| 蒲江县| 鲁甸县| 会宁县| 宁海县| 宿迁市| 土默特右旗| 阿合奇县| 山阳县| 桑日县| 米脂县| 江油市| 延边| 海兴县| 合川市| 西乡县| 荃湾区| 拜泉县| 娄底市| 朝阳区| 溧水县| 东至县| 丰都县| 东平县| 嘉祥县| 鄂托克前旗| 浑源县| 甘孜| 浑源县| 永嘉县| 响水县| 东源县|