Android【布局管理器】——相对布局RelativeLayout
来源:互联网 发布:usb网络共享驱动下载xp 编辑:程序博客网 时间:2024/05/20 15:10
本次实验就是显示如下的activity:
其中只有2个button,1个textview,1个edittext。
实现上面activity比较简单,其xml代码如下:
<span style="font-family:Comic Sans MS;font-size:18px;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10px" > <TextView android:id="@+id/input" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/input_dis" tools:context=".MainActivity" /> <EditText android:id="@+id/edit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/input" android:background="@android:drawable/editbox_background" /> <Button android:id="@+id/ok" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@id/edit" android:layout_alignParentRight="true" android:layout_marginLeft="10px" android:text="@string/ok" /> <Button android:id="@+id/cancel" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@id/edit" android:layout_toLeftOf="@id/ok" android:text="@string/cancel" /></RelativeLayout></span>
在相对布局中有如下属性,解释如下:
// 相对于给定ID控件
android:layout_above 将该控件的底部置于给定ID的控件之上;
android:layout_below 将该控件的底部置于给定ID的控件之下;
android:layout_toLeftOf 将该控件的右边缘与给定ID的控件左边缘对齐;
android:layout_toRightOf 将该控件的左边缘与给定ID的控件右边缘对齐;
android:layout_alignBaseline 将该控件的baseline与给定ID的baseline对齐;
android:layout_alignTop 将该控件的顶部边缘与给定ID的顶部边缘对齐;
android:layout_alignBottom 将该控件的底部边缘与给定ID的底部边缘对齐;
android:layout_alignLeft 将该控件的左边缘与给定ID的左边缘对齐;
android:layout_alignRight 将该控件的右边缘与给定ID的右边缘对齐;
// 相对于父组件
android:layout_alignParentTop 如果为true,将该控件的顶部与其父控件的顶部对齐;
android:layout_alignParentBottom 如果为true,将该控件的底部与其父控件的底部对齐;
android:layout_alignParentLeft 如果为true,将该控件的左部与其父控件的左部对齐;
android:layout_alignParentRight 如果为true,将该控件的右部与其父控件的右部对齐;
// 居中
android:layout_centerHorizontal 如果为true,将该控件的置于水平居中;
android:layout_centerVertical 如果为true,将该控件的置于垂直居中;
android:layout_centerInParent 如果为true,将该控件的置于父控件的中央;
// 指定移动像素
android:layout_marginTop 上偏移的值;
android:layout_marginBottom 下偏移的值;
android:layout_marginLeft 左偏移的值;
android:layout_marginRight 右偏移的值;
续
android:layout_alignParentRight="true"
使当前控件的右端和父控件的右端对齐。这里属性值只能为true或false,默认false。
android:layout_marginLeft="10dip"
使当前控件左边空出相应的空间。
android:layout_toLeftOf="@id/ok"
使当前控件置于id为ok的控件的左边。
android:layout_alignTop="@id/ok"
使当前控件与id控件的上端对齐。
padding表示填充,margin表示边距
可通过android:padding属性进行设置,4个方向的边距属性为android:paddingLeft, android:paddingRight, android:paddingTop, and android:paddingBottom.
结论:
*android:layout_marginBottom
*android:layout_marginLeft
*android:layout_marginRight
*android:layout_marginTop
上面几个属性的值是根据下面的相对位置的对象的值来做计算的,如果没有相对的对象就以总体布局来计算
*android:layout_below
*android:layout_above
*android:layout_toLeftOf
*android:layout_toRightOf
*android:layout_alignTop
*android:layout_centerHrizontal //是否支持横屏或竖屏
*android:layout_centerVertical //这个根据单词的意思:中心垂直
*android:layout_centerInparent //
android:layout_centerInParent="true"//居中在父对象
android:layout_centerInParent="false" ... 浏览器不支持多窗口显示,意思就是说所有页面在单一窗口打开,这样避免了页面布局控制显示问题
下面的相对于父的相对位置
*android:layout_alignParentBottom
*android:layout_alignParentLeft
*android:layout_alignParentRight
*android:layout_alignParentTop
*android:layout_alignWithParentIfMissing
activity的相对布局比较灵活,一些常见的属性也比较多,用得多自然就会了。
- Android【布局管理器】——相对布局RelativeLayout
- Android相对布局管理器RelativeLayout
- RelativeLayout—相对布局
- Android布局———RelativeLayout布局(相对布局)
- Android 相对布局:RelativeLayout
- android 相对布局RelativeLayout
- android 相对布局 RelativeLayout
- Android相对布局(RelativeLayout)
- Android--RelativeLayout相对布局
- Android RelativeLayout相对布局
- Android相对布局RelativeLayout
- Android 相对布局 RelativeLayout
- Android RelativeLayout 相对布局
- Android相对布局(RelativeLayout)
- RelativeLayout——相对布局
- Android学习笔记14:相对布局管理器RelativeLayout
- android开发4:布局管理器1(线性布局,相对布局RelativeLayout-案例)
- 布局管理器——相对布局
- 解决Activity启动黑屏及设置android:windowIsTranslucent不兼容activity切换动画问题
- js获取页面路径的指定参数值
- nginx命令行参数
- camel标记法是什么方法
- 【日常学习】【floyd】codevs1077 多源最短路 题解
- Android【布局管理器】——相对布局RelativeLayout
- IQueryFilter的WhereClause详解
- 第33课第三题
- sqlserver中将varchar类型转换为int型
- 彻底理解ThreadLocal
- UVA--12569(状态压缩+bfs)
- mysql数据库中的日期时间类型
- Linux workqueue工作原理
- 计算Label的高度