Android布局之RelativeLayout
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>
效果图

Android布局之RelativeLayout的更多相关文章
- Android 布局之RelativeLayout
Android 布局之RelativeLayout 1 RelativeLayout简介 RelativeLayout是相对布局. RelativeLayout布局属性 1.1 与parent相对的属 ...
- Android布局及属性归总(查询用)
常见布局 LinearLayout 线性布局 子元素任意,组织成一个单一的水平或垂直行,默认为水平方向TableLayout 表格布局 子元素为<Tabl ...
- Android的学习第六章(布局二--RelativeLayout)
今天我们来说一下Android布局中的Relativelayout布局(相对布局) 根据英译过来意思是相对布局,很容易理解,这一样布局使用的是元素与元素之间的微调做到布局的 含义:通过元素与元素之间的 ...
- android LinearLayout和RelativeLayout实现精确布局
先明确几个概念的区别: padding margin:都是边距的含义,关键问题得明白是什么相对什么的边距padding:是控件的内容相对控件的边缘的边距. margin :是控件边缘相对父空间的边距 ...
- 用android LinearLayout和RelativeLayout实现精确布局(转)
先明确几个概念的区别: padding margin都是边距的含义,关键问题得明白是什么相对什么的边距. padding是控件的内容相对控件的边缘的边距. margin是控件边缘相对父控件的边距. a ...
- [转]用android LinearLayout和RelativeLayout实现精确布局
先明确几个概念的区别: padding margin都是边距的含义,关键问题得明白是什么相对什么的边距. padding是控件的内容相对控件的边缘的边距. margin是控件边缘相对父控件的边距. a ...
- 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 UI布局之RelativeLayout
RelativeLayout是一个相对布局类. 首先RelativeLayout是一个容器,它里边的元素,如Buttonbutton等的位置是依照相对位置来计算的,比如,有两个Buttonbutton ...
随机推荐
- 使用AFNetworking第三方下载类
AFNetworking 眼下使用比較多得一个下载库 眼下一直在维护更新,使用的是很easy 不须要加入不论什么关联的库 1.带block形式 内部是任务队列进行下载 就是对operation的一 ...
- GetKeyState(), GetAsyncKeystate(), GetKeyboardSlate()
GetKeyState.GetAsyncKeyState.GetKeyboardState函数的差别: 1.BOOL GetKeyboardState( PBYTE lpKeyState );获得全部 ...
- RISC-V首度被我国列入扶持对象,上海已成RISC-V重要“据点”
时间:2018年7月24日 16:33 摘要:近期,上海市经济信息委发布了<上海市经济信息化委关于开展2018年度第二批上海市软件和集成电路产业发展专项资金(集成电路和电子信息制造领域)项目申报 ...
- hdoj--3552--I can do it!(贪心模拟)
I can do it! Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Tot ...
- hpuoj--校赛--与学妹滑雪(最短路+精度判断)
问题 G: 感恩节KK专场--与学妹滑雪 时间限制: 1 Sec 内存限制: 128 MB 提交: 284 解决: 25 [提交][状态][讨论版] 题目描述 这周下的雪好大好大,不过这正和KK学 ...
- git ---- 产生冲突的场景 和解决办法
1.git冲突的场景 情景一:多个分支代码合并到一个分支时: 情景二:多个分支向同一个远端分支推送代码时: 实际上,push操作即是将本地代码merge到远端库分支上. 关于push和pull其实就分 ...
- 30.algorithm排序小结
如果容器中是类,如果要调用sort则需要重载操作符 "<" 包含头文件 #define _CRT_SECURE_NO_WARNINGS #include <vector ...
- Future模式 总结
future模式解决异步代码的组织(混入)问题: 类似的解决方案: 1.网络响应的block: 2.SDImageview的自组织.代理模式: 3.顶层响应机制的协议机制:
- 测试cnblog文章内部JS
添加几个按钮 行内js 写法: <button onclick="javascript:alert('行内js')">行内js</button> 注意:al ...
- HDU-4310 Hero 贪心问题
题目链接:https://cn.vjudge.net/problem/HDU-4310 题意 打dota,队友太菜,局势变成1vN.还好你开了挂,hp无限大(攻击却只有一点每秒-_-). 但是你并不想 ...