热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Android学习笔记布局(二)

RelativeLayout(相对布局)相对布局也是android开发中常用的布局.布局同一个界面,相对于线性布局,相对布局嵌套的层数少,性能更佳.相对布局,顾名思义就是相对于其他

RelativeLayout(相对布局)

相对布局也是android开发中常用的布局.布局同一个界面,相对于线性布局,相对布局嵌套的层数少,性能更佳.

相对布局,顾名思义就是相对于其他的控件进行布局.可以通过同级控件制定位置,也可以通过父级控件指定位置.

在相对布局中具有以下属性可以对控件进行布局:

1.android:layout_below 表示当前控件位于指定id控件的下方
2.android:layout_above 表示当前控件位于指定id控件的上方
3.android:layout_toRightOf 表示当前控件位于指定id控件的右方
4.android:layout_toLeftOf 表示当前控件位于指定id控件的左方
5.android:layout_alignTop 表示当前控件与指定id控件顶部对齐
6.android:layout_alignBottom 表示当前控件与指定id控件底部对齐
7.android:layout_alignLeft 表示当前控件与指定id控件左侧对齐
8.android:layout_alignRight 表示当前控件与指定id控件右侧对齐
9.android:layout_alignBaseline 表示当前控件与指定id控件基线对齐
10.android:layout_centerHorizonta l如果指定true表示在父布局水平居中位置
11.android:layout_centerVertical 如果指定true表示在父布局竖直居中位置
12.android:layout_centerInParent 如果指定true表示在父布局竖直水平位置居中
13.android:layout_alignParentTop 如果指定为true表示位于父布局的顶部位置
14.android:layout_alignParentBottom 如果指定为true表示位于父布局的底部位置
15.android:layout_alignParentLeft 如果指定为true表示位于父布局的左侧位置
16.android:layout_alignParentRight 如果指定为true表示位于父布局的右侧位置

以下通过一个demo来总结

效果如下

1 <RelativeLayout xmlns:android&#61;"http://schemas.android.com/apk/res/android"
2 xmlns:tools&#61;"http://schemas.android.com/tools"
3 android:layout_width&#61;"match_parent"
4 android:layout_height&#61;"match_parent"
5 android:background&#61;"&#64;drawable/guide_login_bg"
6 >
7 <ImageView
8 android:id&#61;"&#64;&#43;id/iv_login"
9 android:layout_width&#61;"wrap_content"
10 android:layout_height&#61;"wrap_content"
11 android:layout_centerHorizontal&#61;"true"
12 android:background&#61;"&#64;drawable/no_login_head"
13 />
14 <TextView
15 android:id&#61;"&#64;&#43;id/tv_login"
16 android:layout_width&#61;"wrap_content"
17 android:layout_height&#61;"wrap_content"
18 android:layout_below&#61;"&#64;id/iv_login"
19 android:layout_centerHorizontal&#61;"true"
20 android:text&#61;"登陆"
21 android:textSize&#61;"20sp"
22 android:textColor&#61;"#ffffff"
23 />
24 <TextView
25 android:id&#61;"&#64;&#43;id/tv_line1"
26 android:layout_width&#61;"match_parent"
27 android:layout_height&#61;"1dp"
28 android:background&#61;"#ffffff"
29 android:layout_below&#61;"&#64;id/tv_login"
30 />
31 <RelativeLayout
32 android:id&#61;"&#64;&#43;id/rl_collect"
33 android:layout_width&#61;"wrap_content"
34 android:layout_height&#61;"wrap_content"
35 android:layout_below&#61;"&#64;id/tv_line1"
36 >
37 <ImageView
38 android:id&#61;"&#64;&#43;id/iv_collect"
39 android:layout_width&#61;"wrap_content"
40 android:layout_height&#61;"wrap_content"
41 android:layout_alignParentLeft&#61;"true"
42 android:layout_centerVertical&#61;"true"
43 android:background&#61;"&#64;drawable/icn_01"
44 />
45 <TextView
46 android:id&#61;"&#64;&#43;id/tv_collect"
47 android:layout_width&#61;"wrap_content"
48 android:layout_height&#61;"wrap_content"
49 android:layout_toRightOf&#61;"&#64;id/iv_collect"
50 android:layout_centerVertical&#61;"true"
51 android:text&#61;"我的收藏"
52 android:textSize&#61;"16sp"
53 android:textColor&#61;"#ffffff"
54 />
55 RelativeLayout>
56 <TextView
57 android:id&#61;"&#64;&#43;id/tv_line2"
58 android:layout_width&#61;"match_parent"
59 android:layout_height&#61;"1dp"
60 android:background&#61;"#ffffff"
61 android:layout_below&#61;"&#64;id/rl_collect"
62 />
63 <RelativeLayout
64 android:id&#61;"&#64;&#43;id/rl_message"
65 android:layout_width&#61;"wrap_content"
66 android:layout_height&#61;"wrap_content"
67 android:layout_below&#61;"&#64;id/tv_line2"
68 >
69 <ImageView
70 android:id&#61;"&#64;&#43;id/iv_message"
71 android:layout_width&#61;"wrap_content"
72 android:layout_height&#61;"wrap_content"
73 android:layout_alignParentLeft&#61;"true"
74 android:layout_centerVertical&#61;"true"
75 android:background&#61;"&#64;drawable/icn_02"
76 />
77 <TextView
78 android:id&#61;"&#64;&#43;id/tv_message"
79 android:layout_width&#61;"wrap_content"
80 android:layout_height&#61;"wrap_content"
81 android:layout_toRightOf&#61;"&#64;id/iv_message"
82 android:layout_centerVertical&#61;"true"
83 android:text&#61;"我的消息"
84 android:textSize&#61;"16sp"
85 android:textColor&#61;"#ffffff"
86 />
87 RelativeLayout>
88 <TextView
89 android:id&#61;"&#64;&#43;id/tv_line3"
90 android:layout_width&#61;"match_parent"
91 android:layout_height&#61;"1dp"
92 android:background&#61;"#ffffff"
93 android:layout_below&#61;"&#64;id/rl_message"
94 />
95 <RelativeLayout
96 android:id&#61;"&#64;&#43;id/rl_set"
97 android:layout_width&#61;"wrap_content"
98 android:layout_height&#61;"wrap_content"
99 android:layout_below&#61;"&#64;id/tv_line3"
100 >
101 <ImageView
102 android:id&#61;"&#64;&#43;id/iv_set"
103 android:layout_width&#61;"wrap_content"
104 android:layout_height&#61;"wrap_content"
105 android:layout_alignParentLeft&#61;"true"
106 android:layout_centerVertical&#61;"true"
107 android:background&#61;"&#64;drawable/icn_03"
108 />
109 <TextView
110 android:id&#61;"&#64;&#43;id/tv_set"
111 android:layout_width&#61;"wrap_content"
112 android:layout_height&#61;"wrap_content"
113 android:layout_toRightOf&#61;"&#64;id/iv_set"
114 android:layout_centerVertical&#61;"true"
115 android:text&#61;"我的設置"
116 android:textSize&#61;"16sp"
117 android:textColor&#61;"#ffffff"
118 />
119 RelativeLayout>
120 <TextView
121 android:id&#61;"&#64;&#43;id/tv_line4"
122 android:layout_width&#61;"match_parent"
123 android:layout_height&#61;"1dp"
124 android:background&#61;"#ffffff"
125 android:layout_below&#61;"&#64;id/rl_set"
126 />
127 <RelativeLayout
128 android:id&#61;"&#64;&#43;id/rl_view"
129 android:layout_width&#61;"wrap_content"
130 android:layout_height&#61;"wrap_content"
131 android:layout_below&#61;"&#64;id/tv_line4"
132 >
133 <ImageView
134 android:id&#61;"&#64;&#43;id/iv_view"
135 android:layout_width&#61;"wrap_content"
136 android:layout_height&#61;"wrap_content"
137 android:layout_alignParentLeft&#61;"true"
138 android:layout_centerVertical&#61;"true"
139 android:background&#61;"&#64;drawable/icn_04"
140 />
141 <TextView
142 android:id&#61;"&#64;&#43;id/tv_view"
143 android:layout_width&#61;"wrap_content"
144 android:layout_height&#61;"wrap_content"
145 android:layout_toRightOf&#61;"&#64;id/iv_view"
146 android:layout_centerVertical&#61;"true"
147 android:text&#61;"意見反饋"
148 android:textSize&#61;"16sp"
149 android:textColor&#61;"#ffffff"
150 />
151 RelativeLayout>
152 <TextView
153 android:id&#61;"&#64;&#43;id/tv_line5"
154 android:layout_width&#61;"match_parent"
155 android:layout_height&#61;"1dp"
156 android:background&#61;"#ffffff"
157 android:layout_below&#61;"&#64;id/rl_view"
158 />
159 <RelativeLayout
160 android:id&#61;"&#64;&#43;id/rl_new"
161 android:layout_width&#61;"wrap_content"
162 android:layout_height&#61;"wrap_content"
163 android:layout_below&#61;"&#64;id/tv_line5"
164 >
165 <ImageView
166 android:id&#61;"&#64;&#43;id/iv_new"
167 android:layout_width&#61;"wrap_content"
168 android:layout_height&#61;"wrap_content"
169 android:layout_alignParentLeft&#61;"true"
170 android:layout_centerVertical&#61;"true"
171 android:background&#61;"&#64;drawable/icn_05"
172 />
173 <TextView
174 android:id&#61;"&#64;&#43;id/tv_new"
175 android:layout_width&#61;"wrap_content"
176 android:layout_height&#61;"wrap_content"
177 android:layout_toRightOf&#61;"&#64;id/iv_new"
178 android:layout_centerVertical&#61;"true"
179 android:text&#61;"更新軟件"
180 android:textSize&#61;"16sp"
181 android:textColor&#61;"#ffffff"
182 />
183 RelativeLayout>
184 <TextView
185 android:id&#61;"&#64;&#43;id/tv_line6"
186 android:layout_width&#61;"match_parent"
187 android:layout_height&#61;"1dp"
188 android:background&#61;"#ffffff"
189 android:layout_below&#61;"&#64;id/rl_new"
190 />
191 <RelativeLayout
192 android:id&#61;"&#64;&#43;id/rl_us"
193 android:layout_width&#61;"wrap_content"
194 android:layout_height&#61;"wrap_content"
195 android:layout_below&#61;"&#64;id/tv_line6"
196 >
197 <ImageView
198 android:id&#61;"&#64;&#43;id/iv_us"
199 android:layout_width&#61;"wrap_content"
200 android:layout_height&#61;"wrap_content"
201 android:layout_alignParentLeft&#61;"true"
202 android:layout_centerVertical&#61;"true"
203 android:background&#61;"&#64;drawable/icn_06"
204 />
205 <TextView
206 android:id&#61;"&#64;&#43;id/tv_us"
207 android:layout_width&#61;"wrap_content"
208 android:layout_height&#61;"wrap_content"
209 android:layout_toRightOf&#61;"&#64;id/iv_us"
210 android:layout_centerVertical&#61;"true"
211 android:text&#61;"關於我們"
212 android:textSize&#61;"16sp"
213 android:textColor&#61;"#ffffff"
214 />
215 RelativeLayout>
216 RelativeLayout>

 

转:https://www.cnblogs.com/Jhope/p/5280728.html



推荐阅读
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • 先看看效果是不是自己想要的吧item及item内部控件点击事件不懂的可以先点击查看 ... [详细]
  • 转自:http:malideveloper.arm.comcndevelop-for-malisample-codeetcv1-texture-compression-and-alpha- ... [详细]
  • 一、使用ContentProvider(内容提供者)共享数据ContentProvider在android中的作用是对外共享数据,也就是说 ... [详细]
  • 一、在androidStudio中实现tabs比较简单,新建项目就可以选择tabs模板进行创建,默认实现tabs功能:直接运行项目就可以看到效果:可以说非常简单,但是我们在实际开发 ... [详细]
  • 我正在尝试使用环境变量将DB参数传递给BashOperator,但我找不到任何文档/示例如何使用Jinja模板中的连接。所以我正在寻找类似于变量的东西 ... [详细]
  • 本文介绍了使用kotlin实现动画效果的方法,包括上下移动、放大缩小、旋转等功能。通过代码示例演示了如何使用ObjectAnimator和AnimatorSet来实现动画效果,并提供了实现抖动效果的代码。同时还介绍了如何使用translationY和translationX来实现上下和左右移动的效果。最后还提供了一个anim_small.xml文件的代码示例,可以用来实现放大缩小的效果。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文介绍了Android中的assets目录和raw目录的共同点和区别,包括获取资源的方法、目录结构的限制以及列出资源的能力。同时,还解释了raw目录中资源文件生成的ID,并说明了这些目录的使用方法。 ... [详细]
  • Activiti7流程定义开发笔记
    本文介绍了Activiti7流程定义的开发笔记,包括流程定义的概念、使用activiti-explorer和activiti-eclipse-designer进行建模的方式,以及生成流程图的方法。还介绍了流程定义部署的概念和步骤,包括将bpmn和png文件添加部署到activiti数据库中的方法,以及使用ZIP包进行部署的方式。同时还提到了activiti.cfg.xml文件的作用。 ... [详细]
  • apk简单介绍APK的组成apk安装流程app的启动过程apk打包流程AIDLAIDL介绍为什么要设计这门语言它有哪些语法?默认支持的数据类型包括什么是apk打包流程 ... [详细]
  • Adapter相当于C(Controller,控制器),listView相当于V(View,视图)用于显示数据为ListView提供数据的List,数组或数据库相当于MVC模式中的 ... [详细]
  • 问题说明最近看到Spring事务,在学习过程中遇到一个很苦恼问题搭建好Spring的启动环境后出现了一点小问题在启动时候却出现[java.lang.NullPointerExcep ... [详细]
  • pdf怎么把html变成pdf1 用AdobeAcroat8.1.2,打开网页后,页面右键菜单中会出现一个“转换为AobePDF的选项,点击就可以转换。 安装AdobeAcroba ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
author-avatar
順俟自嘫
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有