如果有一个需求是这样的,在标题中的右上角有一个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. IIS7.0添加IP地址和域名限制

    IIS7.0默认安装是没有“IP地址和域名限制”功能的,需要我们自己选择安装 1.windows系统的添加方式 控制面板--程序与功能--启用或关闭windows功能--internat inform ...

  2. PostgreSQL教程

    https://www.yiibai.com/postgresql/ https://blog.csdn.net/zhangzeyuaaa/article/details/77941039

  3. python 模拟登陆园子

    主要用到了python cookielib,urllib2,urllib这3个模块,python 不亏是具有 先天做 爬虫的特质,废话多说直接上代码 #coding: utf- import sys ...

  4. Macaca 自动化录制工具uirecorder使用入门

    Q&A PC端执行用例前,一定要运行selenium-standalone start,否则会出现这个问题:https://github.com/alibaba/uirecorder/issu ...

  5. HDU 1061.Rightmost Digit-规律题 or 快速幂取模

    Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. 洛谷——P1134 阶乘问题

    P1134 阶乘问题 题目描述 也许你早就知道阶乘的含义,N阶乘是由1到N相乘而产生,如: 12! = 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 ...

  7. 棋盘V

    问题 A: 棋盘V 时间限制: 1 Sec  内存限制: 128 MB提交: 150  解决: 3[提交] [状态] [讨论版] [命题人:] 题目描述 有一块棋盘,棋盘的边长为100000,行和列的 ...

  8. [xsy2363]树

    设$f_{i,j}$表示$i$个点的树,权值为$j$且可以不选根的方案数,$g_{i,j}$表示$i$个点的树,权值为$j$且必选根的方案数 首先$g_{1,1}=0$ 我们可以把原树连上一个新的子树 ...

  9. [HDU6268]Master of Subgraph

    [HDU6268]Master of Subgraph 题目大意: 一棵\(n(n\le3000)\)个结点的树,每个结点的权值为\(w_i\).给定\(m(m\le10^5)\),对于任意\(i\i ...

  10. MathType输入矩阵或者向量的注意事项

    如图A区域是换行搞得,BC是插入矩阵,AC明显看着不一样,就是说行间不要使用换行,列间隔不要用空格(ctrl+shift+space),直接插入矩阵,向量就是矩阵的行或者列数目是1. 还有就是需要注意 ...