Android RelativeLayout属性

Android RelativeLayout属性

转自:http://www.cnblogs.com/hnrainll/archive/2012/03/28/2420901.html

// 相对于给定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   右偏移的值;

example:
android:layout_below = "@id/***"
android:layout_alignBaseline = "@id/***"
android:layout_alignParentTop = true
android:layout_marginLeft = “10px”

[java] view plaincopy
<?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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
RelativeLayoutAndroid中一种常用的布局方式。与其他布局方式不同,RelativeLayout是基于相对位置来放置子视图的。下面是RelativeLayout常用的属性: 1. android:layout_alignParentTop:将子视图放置在父视图的顶部。 2. android:layout_alignParentBottom:将子视图放置在父视图的底部。 3. android:layout_alignParentLeft:将子视图放置在父视图的左侧。 4. android:layout_alignParentRight:将子视图放置在父视图的右侧。 5. android:layout_centerHorizontal:将子视图水平居中放置在父视图中。 6. android:layout_centerVertical:将子视图垂直居中放置在父视图中。 7. android:layout_toLeftOf:将子视图放置在另一个视图的左侧。 8. android:layout_toRightOf:将子视图放置在另一个视图的右侧。 9. android:layout_below:将子视图放置在另一个视图的下方。 10. android:layout_above:将子视图放置在另一个视图的上方。 11. android:layout_alignBaseline:将子视图放置在另一个视图的基线上。 12. android:layout_alignStart:将子视图放置在另一个视图的开始位置上(左侧或顶部)。 13. android:layout_alignEnd:将子视图放置在另一个视图的结束位置上(右侧或底部)。 14. android:layout_alignWithParentIfMissing:如果子视图没有与其他视图对齐,则将其与父视图对齐。 15. android:layout_alignLeft:将子视图左对齐到另一个视图的左侧。 16. android:layout_alignRight:将子视图右对齐到另一个视图的右侧。 17. android:layout_alignTop:将子视图顶部对齐到另一个视图的顶部。 18. android:layout_alignBottom:将子视图底部对齐到另一个视图的底部。 19. android:layout_alignBaseline:将子视图基线对齐到另一个视图的基线。 20. android:layout_alignStart:将子视图的开始位置对齐到另一个视图的开始位置(左侧或顶部)。 21. android:layout_alignEnd:将子视图的结束位置对齐到另一个视图的结束位置(右侧或底部)。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值