06-相对布局和绝对布局
来源:互联网 发布:中国软件邮箱地址 编辑:程序博客网 时间:2024/05/17 23:01
AbsoluteLayout是绝对位置布局。在此布局中的子元素的android:layout_x和android:layout_y属性将生效,用于描述该子元素的坐标位置。屏幕左上角为坐标原点(0,0),第一个0代表横坐标,向右移动此值增大,第二个0代表纵坐标,向下移动,此值增大。在此布局中的子元素可以相互重叠。在实际开发中,通常不采用此布局格式,因为它的界面代码过于刚性,以至于有可能不能很好的适配各种终端。
RelativeLayout按照各子元素之间的位置关系完成布局。在此布局中的子元素里与位置相关的属性将生效。例如android:layout_below, android:layout_above等。子元素就通过这些属性和各自的ID配合指定位置关系。注意在指定位置关系时,引用的ID必须在引用之前,先被定义,否则将出现异常。
相对布局的实例的效果展示:
2.代码
<?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" > <EditText android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignRight="@+id/textView2" android:ems="10" android:hint="@string/reminder" > <requestFocus /> </EditText> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/name" android:text="我的第一个教师节" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/textView1" android:layout_alignParentRight="true" android:layout_alignTop="@+id/textView1" android:layout_marginRight="23dp" android:text="2005年" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView2" android:layout_below="@id/textView2" android:text="确定" /></RelativeLayout>
- 06-相对布局和绝对布局
- 绝对布局和相对布局
- DIV的相对布局和绝对布局
- Duilib六大布局及绝对布局和相对布局
- 理解绝对定位和相对定位布局
- 网页布局,绝对定位和相对定位
- 关于HTML学习重点-绝对布局和相对布局总结
- 绝对布局和相对布局(Relativelayout and Absolutelayout)
- 绝对布局(Relativelayout )和相对布局(Absolutelayout)
- html浮动,相对,绝对布局
- ANDROID 绝对布局 相对布局 Linear…
- 第六周 相对布局与绝对布局
- android的帧布局,绝对布局,相对布局,表格布局
- 【CSS布局.2】绝对定位和相对定位
- CSS网页布局教程:绝对定位和相对定位
- div理解绝对定位和相对定位布局
- CSS教程:相对、绝对定位及布局和浮动
- CSS教程:相对、绝对定位及布局和浮动
- 海量数据处理,转自android小猪
- c++设计模式--策略模式
- Lync 2010升级到Lync 2013 之Lync 2010 架构扩展准备!
- 开发日记(一)
- 我的第一篇博文
- 06-相对布局和绝对布局
- 我或将离开技术的世界, 踏上新的旅程
- centos安装LAMP
- .mysqladmin: Can't turn off logging; error: 'Access denied; you need the SUPER privilege for this op
- 八月的日子
- dcmtk提示无法解析的外部符号(unresolved external symbol)的解决方法
- android上gl纹理资源路径的问题
- PHP中try{}catch{}的具体用法详解
- 面试题之——对包含汉字的字符串截取指定字节数