Android-RelativeLayout布局技巧(一)
如果有一个需求是这样的,在标题中的右上角有一个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布局技巧(一)的更多相关文章
- Android RelativeLayout 布局android:layout_centerHorizontal="true"注意
特别注意,如果要是 android:layout_alignTop="@id/bind_decode_item_layout" android:layout_centerHoriz ...
- android界面布局技巧(一)
(1)//得到手机的宽高 Display display = getWindowManager().getDefaultDisplay(); int screenWidth = display.get ...
- Android学习笔记之布局技巧以及布局中的细节介绍....
PS:休息两天,放一放手上的东西,做做总结... 学习内容: 1.Android中LinearLayout布局技巧... 2.layout中drawable属性的区别... 先简单的介绍一下dra ...
- Android开发——布局性能优化的一些技巧(一)
0. 前言 上一篇我们分析了为什么LinearLayout会比RelativeLayout性能更高,意义在于分析了这两种布局的实现源码,算是对一个小结论的证明过程,但是对布局性能的优化效果,对这两种布 ...
- Android——android相对布局(RelativeLayout)及属性
RelativeLayout布局 android:layout_marginTop="25dip" //顶部距离 android:gravity="left" ...
- Android相对布局(RelativeLayout)
Android相对布局(RelativeLayout) 备注:这里的视图和元素是等同的概念. RelativeLayout是一个允许子视图相对于其他兄弟视图或是父视图显示的视图组(通过ID指定).每个 ...
- 个人经验 - Android的RelativeLayout布局的layout_height属性设置为wrap_content时的坑
Android的RelativeLayout布局的layout_height属性设置为wrap_content时的坑: 此坑出现的条件: 1.RelativeLayout布局的layout_heigh ...
- Android UI -- 布局介绍(布局包括FrameLayout, LinearLayout, RelativeLayout, GridLayout)
首先介绍常用布局类 FrameLayout 最简单的布局管理器. 这个布局管理类有几个特性: 添加组件默认在左上角的. 如果添加多个组件会叠加到一起,并且都在左上角.(可以通过一gravity属性改变 ...
- Android 五大布局(LinearLayout、FrameLayout、AbsoulteLayout、RelativeLayout、TableLayout )
前言 欢迎大家我分享和推荐好用的代码段~~ 声明 欢迎转载,但请保留文章原始出处: CSDN:http://www.csdn.net ...
- android:layout_alignleft layout_toleftof区别,详解RelativeLayout布局属性
转载请注明博客地址. 最近看博客看到有关于RelativeLayout布局的解释,有的解释很多是错误的.因此有必要对每一个常见的布局属性进行描述.以下解释全部都是逐行进行测试的. 首先把常用的布局分组 ...
随机推荐
- springBoot Feign Hystrix Dashboard
1.引入依赖 <!-- 引入关于 hystrix Dashboard的依赖 --> <dependency> <groupId>org.springframewor ...
- Jmeter 监控远程服务器
压力测试中如何监控服务器的性能呢? 性能选取哪些指标? 环境配置: Jmeter安装路径:E:\SOFEWARE\apache-jmeter-3.1: 需要将JMeterPlugins-Extras. ...
- AxureRP7超强部件库打包下载
摘要: 很多刚刚开始学习Axure的朋友都喜欢到网上搜罗各种部件库(组件库)widgets library ,但是网络中真正实用的并且适合你使用的少之又少,最好的办法就是自己制作适合自己工作内容的部件 ...
- 【PKUSC 2015】的一道数学题
有9个人,每三个人中至少有两个互相认识,求证这里面至少有4个人互相认识 PKU官方题解: 引理:二染色K6中一定有同色K3. 证明:考虑某一个点,它一定连出至少三条同色边(不妨设为红边),这三条边连的 ...
- 「Baltic2015」Network
题目描述 原文 The government of Byteland has decided that it is time to connect their little country to th ...
- 【基数排序】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) C. Jon Snow and his Favourite Number
发现值域很小,而且怎么异或都不会超过1023……然后可以使用类似基数排序的思想,每次扫一遍就行了. 复杂度O(k*1024). #include<cstdio> #include<c ...
- 【MySQL笔记】mysql报错"ERROR 1206 (HY000): The total number of locks exceeds the lock table size"的解决方法
step1:查看 1.1 Mysql命令行里输入"show engines:"查看innoddb数据引擎状态, 1.2 show variables "%_buffer% ...
- 使用eclipse调试MR程序
1)点击菜单中的“运行按钮”,然后选择调试配置 2) 3) 这里配置输入路径和输出路径,注意在eclipse上只是在单机模式下Hadoop不会使用HDFS,也不会开启任何Hadoop守护进程,所有程序 ...
- Android之Activity 生命周期
作用:用户界面的组件,主要用于和用户进行交互.可以理解为手机屏幕的一屏. 生命周期: Resume:“继续”的意思. 由此可见, Activity有四种基本状态: 1) Running:位于屏幕最前端 ...
- Oracle RAC 环境下的 v$log v$logfile
通常情况下,在Oracle RAC 环境中,v$视图可查询到你所连接实例的相关信息,而gv$视图则包含所有实例的信息.然而在RAC环境中,当我们查询v$log视图时说按照常理的话,v$log视图应当看 ...