Android-相对布局(RelativeLayout)
<?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.相对与和自己平级的控件 </RelativeLayout> 虽然相对布局需要对没有控件设置ID,才能使用,看起来LinearLayout方便写,实际上RelativeLayout更加对灵活,因为线性布局设置垂直或者水平就整版都是垂直与水平的,相对布局控制更加灵活写 相对布局,如果不指定ID,默认都是在左上角

相对bt_444控件中间线对齐:
android:layout_alignBaseline="@id/bt_333"

相对bt_444控件顶部对齐:
android:layout_alignTop="@id/bt_333"

相对bt_444控件的底部对齐:
android:layout_alignBottom="@id/bt_333"

<!--
相对于父控件系列: 相对于父控件垂直居中
android:layout_centerVertical="true" 相对于父控件水平居中
android:layout_centerHorizontal="true" 相对于父控件正中间
android:layout_centerInParent="true" 相对于父控件的右边
android:layout_alignParentRight="true" 相对于父控件的左边
android:layout_alignParentLeft="true" 相对于父控件的顶部
android:layout_alignParentTop="true" 相对于父控件的底部
android:layout_alignParentBottom="true" 相对于父控件的结束(通常情况下是在父控件最右边)
android:layout_alignParentEnd="true" 相对于父控件的开始 最左边 相对布局的默认
android:layout_alignParentStart="true" 相对于平级控件系列: 相对于bt_111控件的底部
android:layout_below="@+id/bt_111" 相对于bt_111控件的顶部
android:layout_above="@id/bt_111" 相对于bt_111控件的右边
android:layout_toRightOf="@id/bt_111" 相对于bt_111控件的左边
android:layout_toRightOf="@id/bt_111" 相对与控件的中间对齐
android:layout_alignBaseline="@id/bt_333" 相对与控件的顶部对齐
android:layout_alignTop="@id/bt_333" 相对与控件的底部对齐
android:layout_alignBottom="@id/bt_333" 相对与控件的中间对齐
android:layout_alignBaseline="@id/bt_333" 相对与控件的左对齐
android:layout_alignLife="@id/bt_333" 相对与控件的右对齐
android:layout_alignRight="@id/bt_333" // 外边距 上下左右 一般情况下用于 View
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginBottom="20dp"
android:layout_marginRight="20dp"
android:layout_margin="20dp" 外边距往水平方向80dp
android:layout_marginHorizontal="80dp" 外边距往垂直方向80dp
android:layout_marginVertical="80dp" // 内边距 上下左右 一般情况下用于 ViewGroup 用来管控View
android:padding="40dp"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:paddingTop="40dp"
android:paddingBottom="40dp" 内边距往水平方向60dp
android:paddingHorizontal="60dp" 内边距往垂直方向60dp
android:paddingVertical="60dp"
-->
相对布局测试的代码:
<?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"
android:orientation="vertical"> <Button
android:id="@+id/bt_111"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1111" android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true" /> <Button
android:id="@+id/bt_222"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2222"
android:layout_toLeftOf="@id/bt_111"
android:layout_centerInParent="true"
/> <Button
android:id="@+id/bt_333"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:text="333"
android:layout_marginLeft="130dp"
android:layout_marginTop="130dp"
android:background="#f00"
/> <Button
android:id="@+id/bt_444"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="444"
android:layout_toRightOf="@id/bt_333"
android:layout_alignBaseline="@id/bt_333"
android:background="@color/colorAccent"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="555"
android:layout_alignParentStart="true"
/> </RelativeLayout>
Android-相对布局(RelativeLayout)的更多相关文章
- Android相对布局(RelativeLayout)
Android相对布局(RelativeLayout) 备注:这里的视图和元素是等同的概念. RelativeLayout是一个允许子视图相对于其他兄弟视图或是父视图显示的视图组(通过ID指定).每个 ...
- Android之布局RelativeLayout
线性布局的weight属性在等比例分配时比较方便,但是对复杂的界面,嵌套多层LinearLayout布局会导致渲染变慢,占用更多系统资源:而使用RelativeLayout的话,可能仅仅需要一层就可以 ...
- android的布局-----RelativeLayout(相对布局)
学习导图 注:父容器定位的属性值只能是Boolean ,兄弟组件定位的属性值只能是ID 典型案例(梅花) <?xml version="1.0" encoding=" ...
- Android UI -- 布局介绍(布局包括FrameLayout, LinearLayout, RelativeLayout, GridLayout)
首先介绍常用布局类 FrameLayout 最简单的布局管理器. 这个布局管理类有几个特性: 添加组件默认在左上角的. 如果添加多个组件会叠加到一起,并且都在左上角.(可以通过一gravity属性改变 ...
- Android 自学之相对布局 RelativeLayout
相对布局(RelativeLayout),相对布局容器内子组件的位置总是相对兄弟组件.父容器来决定的. RelativeLayout的XML属性及相关方法说明 XML属性 相关方法 说明 androi ...
- [Irving]Android 常用布局之RelativeLayout
RelativeLayout相对布局 相对布局 RelativeLayout 允许子元素指定它们相对于其父元素或兄弟元素的位置,这是实际布局中最常用的布局方式之一. 它灵活性大很多,当然属性也多,操作 ...
- 一步一步学android之布局管理器——RelativeLayout
今天开始学习RelativeLayout(相对布局),相对布局在平时布局的时候用的较多,因为Android适配方面的原因.相对布局可以控制组件摆放的位置(放在任一组件的上下左右等位置),下面来看看类的 ...
- Android 五大布局(LinearLayout、FrameLayout、AbsoulteLayout、RelativeLayout、TableLayout )
前言 欢迎大家我分享和推荐好用的代码段~~ 声明 欢迎转载,但请保留文章原始出处: CSDN:http://www.csdn.net ...
- android LinearLayout和RelativeLayout实现精确布局
先明确几个概念的区别: padding margin:都是边距的含义,关键问题得明白是什么相对什么的边距padding:是控件的内容相对控件的边缘的边距. margin :是控件边缘相对父空间的边距 ...
- .Net程序猿玩转Android开发---(7)相对布局RelativeLayout
相对布局RelativeLayout是Android布局中一个比較经常使用的控件,使用该控件能够布局出适合各种屏幕分辨率的布局,RelativeLayout採用相对位置进行 ...
随机推荐
- [Z] Linux下进程的文件访问权限
原文链接:http://blog.csdn.net/chosen0ne/article/details/10581883 对进程校验文件访问权限包括两个部分,一是确定进程的角色(属于哪个用户或者组), ...
- MongoDB出现CPU飚高,如何强制停止正在执行的操作
如果发出了一个执行耗时很长的任务给MongoDB服务器,客户端强制终止会导致任务依然在服务器端执行. 这时MongoDB提供了查询和管理正在执行任务的方式. // db.currentOp() 获得当 ...
- 初识tornado
Tornado 参考: http://www.cnblogs.com/wupeiqi/articles/5702910.html Tornado 是 FriendFeed 使用的可扩展的非阻塞式 w ...
- 【转】tcp_tw_recycle和tcp_timestamps导致connect失败问题
(2012-02-01 18:40:32) 近来线上陆续出现了一些connect失败的问题,经过分析试验,最终确认和proc参数tcp_tw_recycle/tcp_timestamps相关: ...
- Custom Draw 基础(转载)
common control 4.7版本介绍了一个新的特性叫做Custom Draw,这个名字显得模糊不清,让人有点摸不着头脑,而且MSDN里也只给出了一些如风的解释和例子,没有谁告诉你你想知道的,和 ...
- javaScript字符串操作
JS自带函数concat将两个或多个字符的文本组合起来,返回一个新的字符串.var a = "hello";var b = ",world";var c = a ...
- TCP端口状态说明ESTABLISHED、TIME_WAIT、 CLOSE_WAIT
一. 首先说下tcp端口的几种状态: 1.LISTENING状态 FTP服务启动后首先处于侦听(LISTENING)状态. 2.ESTABLISHED状态 ESTABLISHED的意思是建立连接.表示 ...
- 虚拟机安装centos发现inet为127.0.0.1,导致Xshell连接不上
问题如标题所示: 设置网卡开机自动启动: 实质linux是看一个网卡文件的配置,就是/etc/sysconfig/network-scripts/ifcfg-eth0 (这个文件名看你网卡名称而异,具 ...
- 从HiveQL到MapReduce job过程简析
一.简述 HiveQL是一种声明式语言,用户提交查询,而Hive会将其转换成MapReduce job,如下图.一般来说大部分时间可以无视这个执行过程的内部逻辑,但是如果能了解这些底层实现细节,在调优 ...
- eclipse 使用 scons 编译的配置说明
eclipse版本: eclipse-cpp-kepler-SR1-win32.zip 创建项目必须选择“Makefile Project” 然后进入“Projects Properities” 先 ...