相对布局RelativeLayout详解.docx

上传人:b****5 文档编号:7371013 上传时间:2023-05-11 格式:DOCX 页数:11 大小:268.50KB
下载 相关 举报
相对布局RelativeLayout详解.docx_第1页
第1页 / 共11页
相对布局RelativeLayout详解.docx_第2页
第2页 / 共11页
相对布局RelativeLayout详解.docx_第3页
第3页 / 共11页
相对布局RelativeLayout详解.docx_第4页
第4页 / 共11页
相对布局RelativeLayout详解.docx_第5页
第5页 / 共11页
相对布局RelativeLayout详解.docx_第6页
第6页 / 共11页
相对布局RelativeLayout详解.docx_第7页
第7页 / 共11页
相对布局RelativeLayout详解.docx_第8页
第8页 / 共11页
相对布局RelativeLayout详解.docx_第9页
第9页 / 共11页
相对布局RelativeLayout详解.docx_第10页
第10页 / 共11页
相对布局RelativeLayout详解.docx_第11页
第11页 / 共11页
亲,该文档总共11页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

相对布局RelativeLayout详解.docx

《相对布局RelativeLayout详解.docx》由会员分享,可在线阅读,更多相关《相对布局RelativeLayout详解.docx(11页珍藏版)》请在冰点文库上搜索。

相对布局RelativeLayout详解.docx

相对布局RelativeLayout详解

相对布局:

RelativeLayout

RelativeLayout布局

RelativeLayout顾名思义,相对布局,在这个容器内部的子元素们可以使用彼此之间的位置或则和容器间的相对位置来进行定位。

注意:

不能在RelativeLayout容器本身和他的子元素之间产生依赖,比如说不能将RelativeLayout的高设置成为WRAP_CONTENT的时候将子元素的高度设置成为ALIGN_PARENT_BOTTOM.

与RelativeLayout布局相关的几个属性:

控件与控件之间位置相关的:

android:

layout_above将该控件置于给定ID的控件之上。

android:

layout_below将该控件置于给定ID的控件之下。

android:

layout_toLiftOf将该控件置于给定ID的控件之左。

android:

layout_toRightOf将该控件置于给定ID的控件之右。

控件与控件之间对齐相关的:

android:

layout_alignBaseline该控件基线对齐给定ID的基线。

android:

layout_alignBottom该控于给定ID的控件底部对齐。

android:

layout_alignLift该控于给定ID的控件左对齐。

android:

layout_alignRight该控于给定ID的控件右对齐。

android:

layout_alignTop该控于给定ID的控件顶部对齐。

控件和它的容器之间的关系:

android:

layout_alignParentLift如果为True,该控件位于父控件的左部。

android:

layout_alignParentRight如果为True,该控件位于父控件的右部。

android:

layout_alignTop如果为True,该控件位于父控件的顶部。

android:

layout_alignBottom如果为True,该控件位于父控件的底部。

控件和它的容器位置之间的关系:

android:

layout_centerVertical如果为Ture,该控件将被置于水平方向的中央。

android:

layout_centerHorizontal如果为Ture,该控件将被置于垂直方向的中央。

android:

layout_centerInParent如果为Ture,该控件将被置于父控件水平方向和垂直方向。

 

android="

xmlns:

tools="

android:

layout_width="match_parent"

android:

layout_height="match_parent"

>

android:

id="@+id/txt1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="测试RelativeLayout111111111"

android:

background="#aa0000"/>

android:

id="@+id/txt2"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="测试RelativeLayout2222"

android:

background="#0000aa"

android:

layout_below="@id/txt1"111//与txt1(按钮)下方

android:

layout_alignRight="@id/txt1"/>222//与txt1(按钮)右对齐

 

android="

xmlns:

tools="

android:

layout_width="match_parent"

android:

layout_height="match_parent"

>

android:

id="@+id/txt1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

layout_alignParentBottom="true"333//是在底部的时候

android:

text="测试RelativeLayout111111111"

android:

background="#aa0000"/>

android:

id="@+id/txt2"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="测试RelativeLayout2222"

android:

background="#0000aa"

android:

layout_above="@id/txt1"111

android:

layout_alignRight="@id/txt1"/>

 

 

android="

xmlns:

tools="

android:

layout_width="match_parent"

android:

layout_height="match_parent"

>

android:

id="@+id/txt1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="测试RelativeLayout111111111"

android:

background="#aa0000"

android:

layout_centerInParent="true"/>

 

 

android="

xmlns:

tools="

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

background="#dddd00"

android:

padding="10dp">

android:

id="@+id/textview1"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

text="Thememain:

"/>

android:

id="@+id/edittext1"

android:

layout_width="match_parent"

android:

layout_height="wrap_content"

android:

layout_below="@id/textview1"

/>

android:

id="@+id/button1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="按钮1"

android:

layout_below="@id/edittext1"//id为edittext的下面

android:

layout_alignParentRight="true"/>//是在父件的右部

android:

id="@+id/button2"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="按钮2"

android:

layout_below="@id/edittext1"//在id为edittext1的下面

android:

layout_toLeftOf="@id/button1"/>//在id为button1的左边

 

加拉:

在RelativeLayout里加

android:

padding="10dp"

 

也可以在EditText里加控制它的maygin左右的距离就可以啦

 

android="

xmlns:

tools="

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

background="#dddd00"

>

android:

id="@+id/textview1"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

text="Thememain:

"

android:

layout_marginBottom="20dp"/>

android:

id="@+id/edittext1"

android:

layout_width="match_parent"

android:

layout_height="wrap_content"

android:

layout_below="@id/textview1"

/>

android:

id="@+id/button1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="按钮1"

android:

layout_below="@id/edittext1"

android:

layout_alignParentRight="true"

android:

layout_marginLeft="30dp"/>

android:

id="@+id/button2"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="按钮2"

android:

layout_below="@id/edittext1"

android:

layout_toLeftOf="@id/button1"/>

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2