RelativeLayout布局下实现控件平分空间
起源:使用惯LinearLayout的朋友都知道,若想实现对屏幕的等分,只需要设置Layout_weight的值即可。
可是在RelativeLayout布局下实现等分却不是那么容易。
下面就简单介绍如何在RelativeLayout下实现控件平分空间。
原理简单略带技巧,大家一看就懂。
首先来实现水平等分。
关键在于设置参照物,确定控件的方位。
关键代码如下:
<RelativeLayout
android:layout_width= "match_parent"
android:layout_height= "120dp">
<!-- 设置参照物 -->
<View
android:id= "@+id/strut"
android:layout_width= "0dp"
android:layout_height= "0dp"
android:layout_centerVertical="true" /> <ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@id/strut"
android:layout_alignParentTop="true"
android:background="@drawable/bg_red"/> <ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="@id/strut"
android:layout_alignParentBottom="true"
android:background="@drawable/bg_blue"/>
</RelativeLayout >
效果图如下:
再次来实现垂直等分,原理与水平相似,只是修改方位。
关键代码如下:
<RelativeLayout
android:layout_width= "match_parent"
android:layout_height= "200dp">
<View
android:id= "@+id/strut"
android:layout_width= "0dp"
android:layout_height= "0dp"
android:layout_centerHorizontal="true" /> <ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignRight="@id/strut"
android:layout_alignParentLeft="true"
android:background="@drawable/hankukko"/> <ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="@id/strut"
android:layout_alignParentRight="true"
android:background="@drawable/chopper"/>
</RelativeLayout >
效果图如下:
尾注:如果想要实现更加复杂的多等分,还是推荐使用LinearLayout设置权重的方法。
转载请注明出处:http://www.cnblogs.com/michaelwong/p/4114945.html
RelativeLayout布局下实现控件平分空间的更多相关文章
- 使用谷歌提供的SwipeRefreshLayout下拉控件,并自定义实现下拉加载的功能
package com.loaderman.swiperefreshdemo; import android.os.Bundle; import android.os.Handler; import ...
- [C#]Winform下回车或Tab键自动切换下一个控件焦点
满足用户体验,在数据录入时,能在输入完一个信息后通过回车或Tab键自动的切换到下一个控件(字段). 在界面控件设计时,默认可以通过设置控件的TabIndex来实现.但在布局调整时或者是对输入的内容有选 ...
- js,onblur后下一个控件获取焦点判断、html当前活跃控件、jquery版本查看、jquery查看浏览器版本、setTimeout&setInterval
需求: input控件在失去焦点后直接做验证,验证通不过的话,显示相应错误.但是如果失去焦点后点击的下个控件是比较特殊的控件(比如,退出系统),那么不执行验证操作,直接退出系统(防止在系统退出前,还显 ...
- Delphi下使用Oracle Access控件组下TOraSession控件链接
Delphi下使用Oracle Access控件组下TOraSession控件链接数据库,使用 orsn1.Options.Direct:=true; orsn1.Server:=IP:Port: ...
- ActiveX控件的基本操作方法以及如何在VS2010下使用控件
在此,小编就介绍下ActiveX控件的基本操作方法以及如何在VS2010下使用控件,我们以一个程序为例, (1) 打开VS2010编译器(右键以管理员身份运行,因为ActiveX需要注册), ...
- DevExpress控件GridView挂下拉控件无法对上值
下拉控件使用RepositoryItemLookUpEdit,加入如下事件进行处理. repositoryItemLookUpEdit1.CustomDisplayText += new DevExp ...
- 一不小心写了个bootstrap风格下拉控件 JqueryUI + bootstrap
受够了EasyUI的封闭,Bootstrap虽然华丽但是功能太渣,闲着无聊写个下拉控件玩玩吧,不喜勿喷哈... 第一步:先设计下我的下拉控件的样子 1.既然是bootstrap风格的,我想应该是这样的 ...
- scrollview嵌套下拉控件嵌套recyclerview(不动第三方原基础自定义)
相信会碰到很多类似的需求,一个列表控件,然后控件上方的一个头部需要自定义,这样就不好有时候也不能加在列表控件的头部了,那必须得嵌套一层scrollview了,没毛病,那么一般的列表控件都是有上拉下拉的 ...
- Delphi 获取当前鼠标下的控件内容
Delphi 获取当前鼠标下的控件内容 主要函数: GetCursorPos://获取鼠标的位置 WindowFromPoint://获取制定point下的handle GetClassName:// ...
随机推荐
- c++线程创建传递的参数发生改变
看看如下代码,觉得输出会是什么? #include "stdafx.h" #include <windows.h> #include <iostream> ...
- linux里的bootproto的none,static,dhcp有什么区别
这个是网络配置参数:BOOTPROTO=static 静态IP BOOTPROTO=dhcp 动态IP BOOTPROTO=none 无(不指定)通常情况下是dhcp或者static,通过指定方式 ...
- iOS 倒计时
// // RootViewController.m // MyTimerDemo // // Created by huluo on 1/21/14. // Copyright (c) 2014 b ...
- poj1484---判断保险丝是否烧断
题目输入要求: 2 2 10 //设备数n 接下来的操作数m 保险丝能承受最大电流c5 //电器1的电流7 //2的电流1 //反转开关12 //反转开关2 思路:设置一个flag数组,记得每次 ...
- cnn softmax regression bp求导
内容来自ufldl,代码参考自tornadomeet的cnnCost.m 1.Forward Propagation convolvedFeatures = cnnConvolve(filterDim ...
- (Pre sell) ZOPO ZP998 (C2 II) 5.5 inch smart phone True Octa Core MTK6592 1920X1080 FHD screen 401 ppi 2GB/32GB 14.0Mp camera-in Mobile Phones from Electronics on Aliexpress.com
(Pre sell) ZOPO ZP998 (C2 II) 5.5 inch smart phone True Octa Core MTK6592 1920X1080 FHD screen 401 p ...
- Hibernate 、继承关联映射
一个继承树一张表(subclass) 一个继承树一张表是指将一个类和他下面的所有派生类的所有的属性都放在一张表中,举例有Employee这个实体,在他下面分别派生了两个类skill和sell,通过Hi ...
- g++编译cpp文件
gdb调试c程序打不到断点的原因可能是编译c文件的时候没有加-g选项,-g选项是编译加debug信息的,不加是打不到断点的 g++编译cpp文件 g++ -g -c *.cpp 编译 g+ ...
- shape和selector是Android UI设计中经常用到的
shape和selector是Android UI设计中经常用到的,比如我们要自定义一个圆角Button,点击Button有些效果的变化,就要用到shape和selector.可以这样说,shape和 ...
- Unable to open ...\tools\capture\allegro.cfg for reading
采用Capture CIS 当生成网表.误: Unable to open ...\tools\capture\allegro.cfg for reading. Please correct the ...