android RelativeLayout属性及demo
来源:互联网 发布:网络工程师不是程序员 编辑:程序博客网 时间:2024/06/02 05:31
相对布局由于属性比较多,所以用起来有些费力,但灵活性较其他布局方法好,所以掌握好相对布局将会非常有用。
// 相对于给定ID控件
android:layout_above 将该控件的底部置于给定ID的控件之上;
android:layout_below 将该控件的底部置于给定ID的控件之下;
android:layout_toLeftOf
android:layout_toRightOf
android:layout_alignBaseline
android:layout_alignTop
android:layout_alignBottom
android:layout_alignLeft
android:layout_alignRight
// 相对于父组件
android:layout_alignParentTop
android:layout_alignParentBottom 如果为true,将该控件的底部与其父控件的底部对齐;
android:layout_alignParentLeft
android:layout_alignParentRight
// 居中
android:layout_centerHorizontal 如果为true,将该控件的置于水平居中;
android:layout_centerVertical
android:layout_centerInParent
// 指定移动像素
android:layout_marginTop
android:layout_marginBottom 下偏移的值;
android:layout_marginLeft 左偏移的值;
android:layout_marginRight 右偏移的值;
example:
android:layout_below = "@id/***"
android:layout_alignBaseline = "@id/***"
android:layout_alignParentTop = true
android:layout_marginLeft = “10px”
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Type here:"/> <EditText android:id="@+id/entry" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@android:drawable/editbox_background" android:layout_below="@id/label"/> <Button android:id="@+id/ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/entry" android:layout_alignParentRight="true" android:layout_marginLeft="10dip" android:text="OK" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/ok" android:layout_alignTop="@id/ok" android:text="Cancel" /></RelativeLayout>
这是很常见的布局内容,讲解如下:
android:layout_below="@id/label"/>
将当前控件放置于id为label 的控件下方。android:layout_alignParentRight="true"使当前控件的右端和父控件的右端对齐。这里属性值只能为true或false,默认false。
android:layout_marginLeft="10dip"使当前控件左边空出相应的空间。
android:layout_toLeftOf="@id/ok"使当前控件置于id为ok的控件的左边。
android:layout_alignTop="@id/ok"使当前控件与id控件的上端对齐。
至此,我们已经发现,其属性之繁多。下面简单归纳一下:
第一类:属性值为true或false
*android:layout_centerHrizontal
*android:layout_centerVertical
*android:layout_centerInparent
*android:layout_alignParentBottom
*android:layout_alignParentLeft
*android:layout_alignParentRight
*android:layout_alignParentTop
*android:layout_alignWithParentIfMissing
第二类:属性值必须为id的引用名“@id/id-name”
*android:layout_below
*android:layout_above
*android:layout_toLeftOf
*android:layout_toRightOf
*android:layout_alignTop
第三类:属性值为具体的像素值,如30dip,40px
*android:layout_marginBottom
*android:layout_marginLeft
*android:layout_marginRight
*android:layout_marginTop
- android RelativeLayout属性及demo
- RelativeLayout布局及属性
- android RelativeLayout常用属性
- Android RelativeLayout 属性
- Android RelativeLayout 属性 (
- Android RelativeLayout常用属性~
- android RelativeLayout布局属性
- Android RelativeLayout 属性大全
- Android-----RelativeLayout属性
- Android RelativeLayout 属性
- Android中Relativelayout属性
- 【android RelativeLayout 常用属性】
- Android RelativeLayout 属性
- Android RelativeLayout 属性
- Android RelativeLayout 属性
- android RelativeLayout属性
- Android RelativeLayout 属性
- Android RelativeLayout 属性
- 设计模式之代理模式
- Ubuntu 10.04配置Apache+PHP+MySQL
- Android自动测试之Monkey工具
- ContentType--Http传输中经常看到的参数,从百度上摘的
- Oracle中得blob字段导入到DB2的Blob字段
- android RelativeLayout属性及demo
- Mysql-mmm安装配置文档
- C#中定义可拖动的曲线控件(支持Gamma曲线)
- 在代码中使用 _declspec(dllimport) 和 _declspec(dllexport)
- dom4操纵数据库中的数据生成xml
- Android入门第八篇之GridView(九宫图)
- (ZT)WideCharToMultiByte和MultiByteToWideChar函数的用法
- ffmpeg的IO操作
- 让TableViewer支持Tab编辑