Android布局之RelativeLayout
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Android布局之RelativeLayout,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2913字,纯文字阅读大概需要5分钟。
内容图文
![Android布局之RelativeLayout](/upload/InfoBanner/zyjiaocheng/1226/1758b353f567445e84f4b24d0e7c58a0.jpg)
RelativeLayout用到的一些重要的属性:
第一类:属性值为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 本元素的上边缘和某元素的的上边缘对齐
android:layout_alignLeft 本元素的左边缘和某元素的的左边缘对齐
android:layout_alignBottom 本元素的下边缘和某元素的的下边缘对齐
android:layout_alignRight 本元素的右边缘和某元素的的右边缘对齐
第三类:属性值为具体的像素值,如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" xmlns:tools ="http://schemas.android.com/tools" android:layout_width ="match_parent" android:layout_height ="match_parent" tools:context =".RelativeLayoutActivity" > <!-- alignParent 相对父控件的位置属性 --> < RelativeLayout android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_alignParentBottom ="true" android:id ="@+id/id1" > < Button android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:background ="#23acaa" android:text ="按钮1" /> </ RelativeLayout > <!-- alignParent 相对有id的控件的位置属性 --> < RelativeLayout android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_toRightOf ="@+id/id1" android:layout_above ="@+id/id1" android:id ="@+id/id2" > < Button android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:background ="#23acaa" android:text ="按钮2" /> </ RelativeLayout > <!-- alignParent margin定义间距 --> < RelativeLayout android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_toRightOf ="@+id/id2" android:layout_marginLeft ="20dp" android:layout_marginBottom ="20dp" android:layout_above ="@+id/id2" > < Button android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:background ="#23acaa" android:text ="按钮3" /> </ RelativeLayout > <!-- alignParent center定位居中 --> < RelativeLayout android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_centerHorizontal ="true" android:layout_centerVertical ="true" android:id ="@+id/id4" > < Button android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:background ="#23acaa" android:text ="按钮4" /> </ RelativeLayout > </ RelativeLayout >
效果图
原文:http://www.cnblogs.com/anywherego/p/5405763.html
内容总结
以上是互联网集市为您收集整理的Android布局之RelativeLayout全部内容,希望文章能够帮你解决Android布局之RelativeLayout所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。