020504_相对布局管理器:RelativeLayout.ppt
文本预览下载声明
移动应用开发技术
第5章:布局管理器
——相对布局管理器:RelativeLayout
xfzhaoxd@163.com
本章目标
掌握相对布局管理器的主要特点及使用;
可以使用Activity程序动态增加组件。
相对布局管理器
相对布局管理器指的是参考某一其他控件进行摆放,可以通过控制,将组件摆放在一个指定参考组件的上、下、左、右等位置,这些可以直接通过各个组件提供的属性完成。
No.
属性名称
对应的规则常量
描述
1
android:layout_below
RelativeLayout.BELOW
摆放在指定组件的下边
2
android:layout_toLeftOf
RelativeLayout.LEFT_OF
摆放在指定组件的左边
3
android:layout_toRightOf
RelativeLayout.RIGHT_OF
摆放在指定组件的右边
4
android:layout_alignTop
RelativeLayout.ALIGN_TOP
以指定组件为参考进行上对齐
5
android:layout_alignBottom
RelativeLayout.ALIGN_BOTTOM
以指定组件为参考进行下对齐
6
android:layout_alignLeft
RelativeLayout.ALIGN_LEFT
以指定组件为参考进行左对齐
7
android:layout_alignRight
RelativeLayout.ALIGN_RIGHT
以指定组件为参考进行右对齐
范例:使用相对布局管理器进行组件的排列
?xml version=1.0 encoding=utf-8?
RelativeLayout 定义相对布局管理器
xmlns:android=/apk/res/android
android:id=@+id/AbsoluteLayout01 布局管理器ID,程序使用
android:layout_width=fill_parent 此布局管理器将占据整个屏幕的宽度
android:layout_height=fill_parent 此布局管理器将占据整个屏幕的高度
ImageView 定义图片显示
android:id=@+id/imga 此组件ID,程序中使用
android:src=@drawable/android_mldn_01 显示图片
android:layout_width=wrap_content 组件宽度为图片宽度
android:layout_height=wrap_content / 组件高度为图片高度
ImageView 定义图片显示
android:id=@+id/imgb 此组件ID,程序中使用
android:src=@drawable/android_mldn_02 显示图片
android:layout_width=wrap_content 组件宽度为图片宽度
android:layout_height=wrap_content 组件高度为图片高度
android:layout_toRightOf=@id/imga/ 摆放在imga图片的右边
TextView 定义文本显示组件
android:text=无锡商业职业技术学院 默认显示文字
android:id=@+id/mytext 此组件ID,程序中使用
android:layout_height=wrap_content 组件高度为文字高度
android:layout_width=wrap_content 组件宽度为文字宽度
android:layout_toRightOf=@id/imga 组件摆放在imga图片的右边
android:layout_below=@id/imgb / 组件摆放在imgb图片的下边
Button 定义普通按钮
android:text= 按钮的默认显示文字
android:id=@+id/mybut 此组件ID,程序中使用
android:layout_height=wrap_content 组件高度为文字高度
android:layout_width=wrap_content 组件宽度为文字宽度
android:layout_below=@id/mytext / 此组件摆放在mytext组件之下
/RelativeLayout
相对布局操作类
相对布局的创建可以使用如下两个类完成:
相对布局管理器:Relative
显示全部