参考文章:

http://blog.csdn.net/lizexi486/article/details/7205067

http://www.cnblogs.com/tornadomeet/archive/2012/07/29/2614378.html

一、相对布局属性

android:layout_width 部件的宽度
android:layout_height 部件的高度
android:gravity 部件的内容在部件中的位置

// 相对于给定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:paddingLeft 部件内容与部件左边距离
android:paddingRight 部件内容与部件右边距离
android:paddingTop 部件内容与部件上边距离
android:paddingBottom 部件内容与部件下边距离

二、布局实例

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent" ><TextView    android:id="@+id/text1"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:gravity="bottom"    android:background="#ff0000"    android:text="请输入用户名:"    /><EditText    android:id="@+id/editText1"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:layout_alignParentLeft="true"    android:layout_below="@+id/text1"    android:layout_marginTop="10dp"    android:background="@android:drawable/editbox_background"  /><Button    android:id="@+id/button2"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_alignBottom="@+id/button1"    android:layout_alignParentRight="true"    android:text="取消" /><Button    android:id="@+id/button1"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_below="@id/editText1"    android:layout_toLeftOf="@id/button2"    android:layout_marginTop="10dp"    android:text="确认" /></RelativeLayout>

效果图:


更多相关文章

  1. android TextView 控件居右显示
  2. Android(安卓)xml 深入解析shape
  3. Android(安卓)基本UI控件
  4. Android实现输入法弹出时把布局顶上去和登录按钮顶上去的解决方
  5. Android--ListView 分割线
  6. ListView 常用属性
  7. 380个Android实例
  8. 第21天android:《android从零开始》视频(10-13)
  9. 380个Android实例

随机推荐

  1. Docker 安装 ubuntu、centos
  2. 使用 MongoDB 工具迁移自建数据库上云
  3. RPA 服务端迁移 (从k8s到docker)
  4. kubernetes Event 源码解析
  5. Node.js SDK 核心库安装与调用
  6. Mac 如何编译 PHP 8.0 到 MxSrvs 工具
  7. 在 ECS 实例上部署 Node.js 环境
  8. 在 Ubuntu 和 CentOS 系统中挂载文件系统
  9. Ubuntu 快速更换阿里源
  10. CentOS8 安装 Docker