如果有一个需求是这样的,在标题中的右上角有一个button

     <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@color/pink_light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="标题"
android:layout_centerInParent="true"
/> <Button
android:layout_width="45dp"
android:layout_height="26dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_centerVertical="true"
android:background="@color/green_light"
android:text="更多"
android:textSize="12sp"
/>
</RelativeLayout>
</LinearLayout>

其实上面的例子用到了相对布局的相对父控件,居中,靠右,距离右边多少db。当然相对父控件比较多,我们也给你自己定义一个参照物,比如,我们可以相对标题中的TextView作为参照物

     <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@color/pink_light">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="标题"
android:layout_centerInParent="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="标题2"
android:layout_toRightOf="@+id/title"
android:layout_centerInParent="true"
android:layout_marginLeft="5dp"
/>
</RelativeLayout>
</LinearLayout>

居中参照物

 <RelativeLayout
android:layout_width="match_parent"
android:background="@color/white"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
>
<Button
android:id="@+id/common_dialog_sureBtn"
android:layout_width="@dimen/common_button_width"
android:layout_height="@dimen/common_button_height"
android:background="@drawable/common_click_bule_btn_selector"
android:text="@string/sure"
android:gravity="center"
android:textColor="@color/white"
android:textSize="@dimen/common_words_size"
android:layout_marginRight="30dp"
android:layout_toLeftOf="@+id/target_mid"/>
<View
android:id="@+id/target_mid"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerHorizontal="true"
/>
<Button
android:id="@+id/common_dialog_cancleBtn"
android:layout_width="@dimen/common_button_width"
android:layout_height="@dimen/common_button_height"
android:background="@drawable/common_click_gray_btn_selector"
android:text="@string/cencle"
android:gravity="center"
android:textColor="@color/white"
android:layout_toRightOf="@+id/target_mid"
android:layout_marginLeft="30dp"
android:textSize="@dimen/common_words_size"/>
</RelativeLayout>

此篇主要是 相对参照物

Android-RelativeLayout布局技巧(一)的更多相关文章

  1. Android RelativeLayout 布局android:layout_centerHorizontal="true"注意

    特别注意,如果要是 android:layout_alignTop="@id/bind_decode_item_layout" android:layout_centerHoriz ...

  2. android界面布局技巧(一)

    (1)//得到手机的宽高 Display display = getWindowManager().getDefaultDisplay(); int screenWidth = display.get ...

  3. Android学习笔记之布局技巧以及布局中的细节介绍....

    PS:休息两天,放一放手上的东西,做做总结... 学习内容: 1.Android中LinearLayout布局技巧... 2.layout中drawable属性的区别...   先简单的介绍一下dra ...

  4. Android开发——布局性能优化的一些技巧(一)

    0. 前言 上一篇我们分析了为什么LinearLayout会比RelativeLayout性能更高,意义在于分析了这两种布局的实现源码,算是对一个小结论的证明过程,但是对布局性能的优化效果,对这两种布 ...

  5. Android——android相对布局(RelativeLayout)及属性

    RelativeLayout布局 android:layout_marginTop="25dip" //顶部距离 android:gravity="left" ...

  6. Android相对布局(RelativeLayout)

    Android相对布局(RelativeLayout) 备注:这里的视图和元素是等同的概念. RelativeLayout是一个允许子视图相对于其他兄弟视图或是父视图显示的视图组(通过ID指定).每个 ...

  7. 个人经验 - Android的RelativeLayout布局的layout_height属性设置为wrap_content时的坑

    Android的RelativeLayout布局的layout_height属性设置为wrap_content时的坑: 此坑出现的条件: 1.RelativeLayout布局的layout_heigh ...

  8. Android UI -- 布局介绍(布局包括FrameLayout, LinearLayout, RelativeLayout, GridLayout)

    首先介绍常用布局类 FrameLayout 最简单的布局管理器. 这个布局管理类有几个特性: 添加组件默认在左上角的. 如果添加多个组件会叠加到一起,并且都在左上角.(可以通过一gravity属性改变 ...

  9. Android 五大布局(LinearLayout、FrameLayout、AbsoulteLayout、RelativeLayout、TableLayout )

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...

  10. android:layout_alignleft layout_toleftof区别,详解RelativeLayout布局属性

    转载请注明博客地址. 最近看博客看到有关于RelativeLayout布局的解释,有的解释很多是错误的.因此有必要对每一个常见的布局属性进行描述.以下解释全部都是逐行进行测试的. 首先把常用的布局分组 ...

随机推荐

  1. 移动APP 支付宝快捷支付开发流程

    [代码] [Java]代码 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ...

  2. 如何调用docker swarm service的API来创建及更新服务

    平衡的推进,先作一个原型吧. #!/usr/bin/env python # -*- coding: utf-8 -*- import requests import json #定义docker s ...

  3. 浅谈replace()

    replace()简单介绍 replace()基本语法是String.replace(searchValue,replaceValue),其中searchValue为字符串或者正则,replaceVa ...

  4. Nginx 的安装配置入门(mac)

    1.安装Nginx服务器: 执行命令 brew install nginx 安装完以后,可以在终端输出的信息里看到一些配置路径: /usr/local/etc/nginx/nginx.conf (配置 ...

  5. System Center VMM请注意不同语言版本的差异

    在私有云的项目中,经常需要判断System Center一些组件的连接是否OK. 我这里有开发,和测试两个环境,开发是英文版的System Center VMM,测试用的是中文版的System Cen ...

  6. 完全背包【p1832】A+B Problem(再升级)

    Description 给定一个正整数n,求将其分解成若干个素数之和的方案总数. Input 一行:一个正整数n Output 一行:一个整数表示方案总数 素数之和 ? 背包啊. 没一遍切的题都不是水 ...

  7. 洛谷——P1795 无穷的序列_NOI导刊2010提高(05)

    P1795 无穷的序列_NOI导刊2010提高(05) 题目描述 有一个无穷序列如下: 110100100010000100000… 请你找出这个无穷序列中指定位置上的数字 输入输出格式 输入格式: ...

  8. 服务认证暴力破解工具Crowbar

    服务认证暴力破解工具Crowbar   Crowbar是Kali Linux新增的一款服务认证暴力破解工具.该工具支持OpenVPN.RDP.SSH和VNC服务.该工具具备常见的暴力破解功能,如主机字 ...

  9. 火狐浏览器信息提取工具Dumpzilla

    火狐浏览器信息提取工具Dumpzilla   浏览器会自动保存用户访问网站的各项信息,如Cookie.网址.下载记录.书签等.通过分析这些信息,可以获取使用者的诸多个人信息和行为习惯.Kali Lin ...

  10. Spring Boot企业微信点餐系统-第一章-课程介绍

    一.项目简介——技术要点 前端和后端: 后端主要技术: 微信接口技术 微信支付 微信扫码登录 微信模板消息推送 开发环境 但实际上我用的环境和这上面还是有点不一样,我服务器用的是win,到时候我会详细 ...