Android——RelativeLayout(相对布局)

一、相对于父容器
1.居中
2.同方向
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <!--相对于父容器
1.居中
2.同方向对齐方式
-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮一"
android:layout_centerInParent="true"
/><!--位于父容器居中位置-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮二"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/><!--与父容器底端对齐-->
<!--位于父容器水平居中位置-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮三"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
/><!--与父容器右侧对齐-->
<!--位于父容器垂直居中位置-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮四"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
/><!--与父容器左侧对齐-->
<!--位于父容器垂直居中位置-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮五"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/><!--与父容器顶端对齐-->
<!--位于父容器水平居中位置-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮六"
/><!--与父容器左侧对齐-->
<!--与父容器顶端对齐-->
<!--默认位置-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮七"
android:layout_alignParentRight="true"
/><!--与父容器右侧对齐-->
<!--与父容器顶端对齐-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮八"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/><!--与父容器左侧对齐-->
<!--与父容器底端对齐-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮十"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
/><!--与父容器右侧对齐-->
<!--与父容器底端对齐-->
</RelativeLayout>

二、与兄弟组件的相对位置
1.同方向
2.反方向
+lay_outmargin +padding
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--与兄弟组件之间
1.同方向
2.反方向--> <!--margin 外边距
padding 内间距
-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮一"
android:layout_centerInParent="true"
android:id="@+id/bt"/><!--父容器内居中-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮二"
android:layout_alignTop="@id/bt"
android:layout_toLeftOf="@id/bt"/>
//相对于按钮一 顶部对齐 位于左侧 <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮三"
android:layout_alignRight="@id/bt"
android:layout_above="@id/bt"/>
//相对于按钮一 右侧对齐 位于上方
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮四"
android:layout_alignRight="@id/bt"
android:layout_below="@id/bt"/>
//相对于按钮一 右侧对齐 位于下方
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮五"
android:layout_alignTop="@id/bt"
android:layout_toRightOf="@id/bt"/>
//相对于按钮一 顶部对齐 位于右侧
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮六"
android:layout_toRightOf="@id/bt"
android:layout_below="@id/bt"/>
//相对于按钮一 位于右侧 位于下方
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮七"
android:layout_toRightOf="@id/bt"
android:layout_above="@id/bt"/>
//相对于按钮一 位于右侧 位于上方 <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮八"
android:layout_toLeftOf="@id/bt"
android:layout_above="@id/bt"/>
//相对于按钮一 位于左侧 位于上方 <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮九"
android:layout_toLeftOf="@id/bt"
android:layout_below="@id/bt"/>
//相对于按钮一 位于左侧 位于下方
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="输入框"
android:id="@+id/et"
android:paddingLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"/>
//内左侧间距20dp 上边距20dp 下边距10dp <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:layout_alignParentRight="true"
android:layout_below="@id/et"
android:id="@+id/ok"/>
//ok按钮 位于父窗口右侧 输入框下方
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CANCLE"
android:layout_alignTop="@id/ok"
android:layout_toLeftOf="@id/ok"
android:layout_marginRight="20dp"/>
//cancle按钮 相对于ok按钮顶部对齐 位于左侧 右边距20dp </RelativeLayout>

Android——RelativeLayout(相对布局)的更多相关文章
- Android RelativeLayout相对布局
RelativeLayout是相对布局控件:以控件之间相对位置或相对父容器位置进行排列. 相对布局常用属性: 子类控件相对子类控件:值是另外一个控件的id android:layout_above-- ...
- Android开发重点难点1:RelativeLayout(相对布局)详解
前言 啦啦啦~博主又推出了一个新的系列啦~ 之前的Android开发系列主要以完成实验的过程为主,经常会综合许多知识来写,所以难免会有知识点的交杂,给人一种混乱的感觉. 所以博主推出“重点难点”系列, ...
- Android开发3:Intent、Bundle的使用和ListView的应用 、RelativeLayout(相对布局)简述(简单通讯录的实现)
前言 啦啦啦~博主又来骚扰大家啦~大家是不是感觉上次的Android开发博文有点长呢~主要是因为博主也是小白,在做实验的过程中查询了很多很多概念,努力去理解每一个知识点,才完成了最终的实验.还有就是随 ...
- Android(java)学习笔记164:Relativelayout相对布局案例
我们看看案例代码,自己心领神会: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout ...
- 第13章、布局Layouts之RelativeLayout相对布局(从零開始学Android)
RelativeLayout相对布局 RelativeLayout是一种相对布局,控件的位置是依照相对位置来计算的,后一个控件在什么位置依赖于前一个控件的基本位置,是布局最经常使用,也是最灵活的一种布 ...
- Android开发之布局--RelativeLayout布局
RelativeLayout 相对布局 true或false属性 Layout_centerHorizontal 当控件位于父控件的横向中间位置 Layout_centerVertical 当 ...
- Android精通:TableLayout布局,GridLayout网格布局,FrameLayout帧布局,AbsoluteLayout绝对布局,RelativeLayout相对布局
在Android中提供了几个常用布局: LinearLayout线性布局 RelativeLayout相对布局 FrameLayout帧布局 AbsoluteLayout绝对布局 TableLayou ...
- Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件
UI的描述 对于Android应用程序中,所有用户界面元素都是由View和ViewGroup对象构建的.View是绘制在屏幕上能与用户进行交互的一个对象.而对于ViewGroup来说,则是一个用于存放 ...
- Android(java)学习笔记107:Relativelayout相对布局
1. Relativelayout相对布局案例: 我们看看案例代码,自己心领神会: <?xml version="1.0" encoding="utf-8" ...
随机推荐
- Spring MVC配置CORS(解决跨域请求)
1. CORS 简介 同源策略(same origin policy)是浏览器安全的基石.在同源策略的限制下,非同源的网站之间不能发送 ajax 请求的. 为了解决这个问题,w3c 提出了跨源资源共享 ...
- UDP Sockets in C#
UDP provides an end-to-end service different from that of TCP. In fact, UDP performs only two functi ...
- 利用JqGrid结合ashx及EF分页显示列表之二
上一篇文章简单利用JqGrid及ashx进行一个数据列表的显示,要文的重点是利用EF的分页与JqGrid进行结合,EF本文只是简单运用所以没有很规范,重点还是JqGrid分页的实现;本实例把JqGri ...
- [Exceptions Spring 2] - Cannot create a session after the response has been committed
2016-02-23 14:06:27,416 [http-bio-8080-exec-1] DEBUG [org.springframework.beans.factory.support.Defa ...
- java web 中的MVC
M:相当于Bean V:jsp C:servlet 当客户端发来请求,servlet响应请求处理请求,并把要发送给客户端的数据封装到Bean中,然后通过转发,将这个封装好了数据Bean送给jsp,js ...
- Appium完整安装教程
Appium安装教程 发布时间: 2014-12-11 10:34 作者: 柒月 来源: 51Testing软件测试网采编 字体: 小 中 大 | 上一篇 下一篇 | 打印 | ...
- win7 下配置 java 环境变量[转]
首先,你应该已经安装了 java 的 JDK 了,笔者安装的是:jdk-7u7-windows-x64 接下来主要讲怎么配置 java 的环境变量,也是为了以后哪天自己忘记了做个备份 1.进入“计算机 ...
- IntelliJ Idea各种技巧设置笔记和错误解决
版本控制 GitHub GitHub提示找不到路径: 解决方法:去官方下载gitHub,然后在以下路径找到Git.exe并设置 C:\Users\你的用户\AppData\Local\GitHub\P ...
- Android EditText 赋值与取值
//取值 String strSmsPhone=m_txtSmsPhone.getText().toString(); //赋值 m_txtSmsPhone.setText("你好" ...
- WebSocket的几个模块(node.js)(未完)
1.ws模块 npm install ws 2.nodejs-websocket npm nodejs-websocket 3.socket.io模块 npm install socket.io