前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >RelativeLayout(相对布局)

RelativeLayout(相对布局)

作者头像
欢醉
发布2018-01-22 10:28:50
1.1K0
发布2018-01-22 10:28:50
举报
文章被收录于专栏:james大数据架构james大数据架构

相对布局的子控件会根据它们所设置的参照控件和参数进行相对布局。

参照控件:aclock   控件与容器之间

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组件上边界对齐

效果:

代码:

代码语言:javascript
复制
 1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     tools:context=".AndroidRelativeLayoutActivity" >
 6 
 7     <AnalogClock
 8         android:id="@+id/aclock"
 9         android:layout_width="wrap_content"
10         android:layout_height="wrap_content"
11         android:layout_centerInParent="true" >
12     </AnalogClock>
13 
14         <!--
15 android:layout_below="@id/aclock" 位于模拟时钟下面。如果没有设置属性layout_alignLeft和layout_marginLeft ,
16 该数字时钟会顶到左屏幕边显示;alignLeft="@id/aclock" 和属性layout_below 配合使用,使得该数字时钟和上面的模拟时钟的左边距对齐,
17 如果没有设置marginLeft 属性的话和上面的两个属性配合使用,使得数字时钟距模拟时钟的左边距40个像素
18 
19 -->
20     
21     <DigitalClock
22         android:id="@+id/dclock"
23         android:layout_width="wrap_content"
24         android:layout_height="wrap_content"
25         android:layout_alignLeft="@id/aclock"
26         android:layout_below="@id/aclock"
27         android:layout_marginLeft="40px" >
28     </DigitalClock>
29 
30     <TextView
31         android:layout_width="wrap_content"
32         android:layout_height="wrap_content"
33         android:layout_alignTop="@id/aclock"
34         android:layout_toLeftOf="@id/dclock"
35         android:text="当前时间" >
36     </TextView>
37 
38 </RelativeLayout>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2013-01-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档