android 开发布局之RelativeLayout

相对布局中的视图组件是按相互之间的相对位置来确定的, 并不是线性布局中的必须

按行或按列单个显示,主要属性如下:

相对于某一个元素

android:layout_below="@id/aaa" 该元素在 id为aaa的下面

android:layout_toLeftOf="@id/bbb" 改元素的左边是bbb

相对于父元素

android:layout_alignParentLeft="true"  在父元素左对齐
android:layout_alignParentRight="true" 在父元素右对齐
还可以指定边距等,

android:layout_marginLeft="10dip" 使当前控件左边空出相应的空间。

具体可以详见API,下面简单归纳一下其属性取值:

第一类:属性值为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

如下布局:

<?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:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/name_text"
        android:id="@+id/text"
    />
    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/text"
        android:id="@+id/edit"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/cancle_button"
        android:layout_alignParentRight="true"
        android:layout_below="@id/edit"
        android:id="@+id/cancle"
        />
    <Button
        android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_toLeftOf="@id/cancle"
		android:layout_alignTop="@id/cancle"
		android:text="@string/ok_button"
        />

</RelativeLayout>
显示的效果如下:



参考:http://hi.baidu.com/hoyah/item/ac49b0d059c96ae1b2f777f1

整个android的布局和视图可以参考这篇博文点击打开链接。写的非常全!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值