android:layout_alignParentLeft="true" 位于父容器左上角 android:layout_alignParentBottom, android:layout_alignParentTop, android:layout_alignParentRight  只能在父控件为RelativeLayout时才起作用,而对于像LinearLayout这样的布局不起作用

android:layout_centerInParent="true" 位于布局容器的中央位置;

layout_centerHorizontal位于布局容器水平居中位置;

layout_centerVertical位于布局容器垂直居中位置

被参照控件:控件与控件之间位置

android:layout_below="@id/aclock" 位于aclock组件下方

android:layout_toLeftOf="@id/dclock"位于dclock组件左则

控件与控件之间对齐方式  

android:layout_alignLeft="@id/aclock"与aclock组件左边界对齐;

android:layout_alignTop="@id/aclock"与aclock组件上边界对齐

效果:

<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=".AndroidRelativeLayoutActivity" >

<AnalogClock
android:id="@+id/aclock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
</AnalogClock>

<!--
android:layout_below="@id/aclock" 位于模拟时钟下面。如果没有设置属性layout_alignLeft和layout_marginLeft ,
该数字时钟会顶到左屏幕边显示;alignLeft="@id/aclock" 和属性layout_below 配合使用,使得该数字时钟和上面的模拟时钟的左边距对齐,
如果没有设置marginLeft 属性的话和上面的两个属性配合使用,使得数字时钟距模拟时钟的左边距40个像素

-->

<DigitalClock
android:id="@+id/dclock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/aclock"
android:layout_below="@id/aclock"
android:layout_marginLeft="40px" >
</DigitalClock>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/aclock"
android:layout_toLeftOf="@id/dclock"
android:text="当前时间" >
</TextView>

</RelativeLayout>

android 布局居中的更多相关文章

  1. Android布局居中的几种做法

    Android的布局文件中,如果想让一个组件(布局或View)居中显示在另一个布局(组件)中,可以由这么几种做法: android:layout_gravity android:gravity and ...

  2. android布局居中

    添加android:gravity="center" 或者android:layout_gravity="center"属性.android:gravity用于 ...

  3. Android 布局之FrameLayout

    Android 布局之FrameLayout 1 FrameLayout简介 对于FrameLayout,官方介绍是:FrameLayout is designed to block out an a ...

  4. android布局常用属性记录

    android布局常用属性记录   http://blog.csdn.net/xn4545945/article/details/7717086这里有一部分别人总结的其余的: align:对齐 par ...

  5. Android 布局详解

    Android 布局详解 1.重用布局 当一个布局文件被多处使用时,最好<include>标签来重用布局. 例如:workspace_screen.xml的布局文件,在另一个布局文件中被重 ...

  6. Android布局及属性归总(查询用)

    常见布局 LinearLayout    线性布局        子元素任意,组织成一个单一的水平或垂直行,默认为水平方向TableLayout    表格布局        子元素为<Tabl ...

  7. Android布局管理详解(1)—— LinearLayout 线性布局

    Android的布局方式共有6种,分别是LinearLayout(线性布局).TableLayout(表格布局).FrameLayout(帧布局).RelativeLayout(相对布局).GridL ...

  8. ZT Android布局】在程序中设置android:gravity 和 android:layout_Gravity属性

    Android布局]在程序中设置android:gravity 和 android:layout_Gravity属性 分类: [Android基础] 2011-04-19 16:06 54739人阅读 ...

  9. Android布局需要知道的基础知识

    eclipse配置环境变量: 1.在 eclipse 中的 Window --> preferences  --> Android(安装了ADT的前提下才能看到Android) --> ...

随机推荐

  1. MessageBox.Show()如何换行

    MessageBox.Show("你好!\n\r可以使用", "换行");

  2. linux上tomcat安装

    转载:http://my.oschina.net/zmf/blog/309484 tomcat安装 下载后解压:tar -zxvf apache-tomcat-7.0.28 移动到/usr/local ...

  3. ApplePay扩大全球发卡行合作,“苹果税”撑不住了?

    5月11日Apple Pay全面登陆加拿大地区,更为重要的是,苹果终于在一些地区,开始和美国运通之外的发卡行达成了合作.这对于老是因为分账问题不愿意走出下一步的Apple Pay来说,已经是巨大的进步 ...

  4. WCF入门(二)-----实战开发

    在这个实战中我们将使用DataContract,ServiceContract来构建WCF服务,并使用VS2008内置的“WCFSVCHost”运行我们创建的WCF服务,并使用“WCF测试客户端”来测 ...

  5. 关于Linux的时间与时区

    转:http://linux.chinaunix.net/techdoc/beginner/2007/06/22/960790.shtml 首先要说明的是我的系统是fedora,其他系统可能不完全相同 ...

  6. AndroidRichText 让Textview轻松的支持富文本(图像ImageSpan、点击效果等等类似QQ微信聊天)

    代码地址:https://github.com/Luction/AndroidRichText AndroidRichText帮助实现像QQ,微信一样的,一个TextView里既有文字又有表情又有图片 ...

  7. jquery index()方法

    搜索匹配的元素,并返回相应元素的索引值,从0开始计数. 如果不给 .index() 方法传递参数,那么返回值就是这个jQuery对象集合中第一个元素相对于其同辈元素的位置.        如果参数是一 ...

  8. javascript grunt安装和使用

    grunt是javascript世界的构建工具. 为何要用构建工具? 一句话:自动化.对于需要反复重复的任务,例如压缩(minification).编译.单元测试.linting等.自动化工具可以减轻 ...

  9. SQL server函数大全

    函数类别 作用 聚合函数 执行的操作是将多个值合并为一个值.例如 COUNT.SUM.MIN 和MAX. 配置函数 是一种标量函数,可返回有关配置设置的信息. 转换函数 将值从一种数据类型转换为另一种 ...

  10. Apache端口配置

    找到配置文件 httpd.conf  并用编辑器打开. 在添加端口之前,我们可以查看端口是否已经被开启,命令如下: window查看端口: # 查看所有端口$ netstat -n -a# 查看 80 ...