Android应用开发学习笔记之相对布局
来源:互联网 发布:破解密码的软件 编辑:程序博客网 时间:2024/06/06 01:33
作者:刘昊昱
博客:http://blog.csdn.net/liuhaoyutz
相对布局RelativeLayout是指按照组件之间的相对位置进行布局,如一个组件在另一个组件的左边、右边、上边或下边等。
RelativeLayout常用的XML属性有:
android:gravity
用于设置布局管理器中各子组件的对齐方式。
android:ignoreGravity
用于指定哪个组件不受gravity属性的影响。
在相对布局管理器中,如果只有上面两个属性是远远不够的,为了更好地控制该布局管理器中的组件,RelativeLayout提供了一个内部类:RelativeLayout.LayoutParams,通过该类提供的大量XML属性,可以很好的控制RelativeLayout中的各组件的布局。
下表是Android官方网站上给出的RelativeLayout.LayoutParams的XML属性
Attribute Name
Description
android:layout_above
Positions the bottom edge of this view above the given anchor view ID.
android:layout_alignBaseline
Positions the baseline of this view on the baseline of the given anchor view ID.
android:layout_alignBottom
Makes the bottom edge of this view match the bottom edge of the given anchor view ID.
android:layout_alignEnd
Makes the end edge of this view match the end edge of the given anchor view ID.
android:layout_alignLeft
Makes the left edge of this view match the left edge of the given anchor view ID.
android:layout_alignParentBottom
If true, makes the bottom edge of this view match the bottom edge of the parent.
android:layout_alignParentEnd
If true, makes the end edge of this view match the end edge of the parent.
android:layout_alignParentLeft
If true, makes the left edge of this view match the left edge of the parent.
android:layout_alignParentRight
If true, makes the right edge of this view match the right edge of the parent.
android:layout_alignParentStart
If true, makes the start edge of this view match the start edge of the parent.
android:layout_alignParentTop
If true, makes the top edge of this view match the top edge of the parent.
android:layout_alignRight
Makes the right edge of this view match the right edge of the given anchor view ID.
android:layout_alignStart
Makes the start edge of this view match the start edge of the given anchor view ID.
android:layout_alignTop
Makes the top edge of this view match the top edge of the given anchor view ID.
android:layout_alignWithParentIfMissing
If set to true, the parent will be used as the anchor when the anchor cannot be be found for layout_toLeftOf, layout_toRightOf, etc.
android:layout_below
Positions the top edge of this view below the given anchor view ID.
android:layout_centerHorizontal
If true, centers this child horizontally within its parent.
android:layout_centerInParent
If true, centers this child horizontally and vertically within its parent.
android:layout_centerVertical
If true, centers this child vertically within its parent.
android:layout_toEndOf
Positions the start edge of this view to the end of the given anchor view ID.
android:layout_toLeftOf
Positions the right edge of this view to the left of the given anchor view ID.
android:layout_toRightOf
Positions the left edge of this view to the right of the given anchor view ID.
android:layout_toStartOf
Positions the end edge of this view to the start of the given anchor view ID.
下面我们来看一个例子,该程序运行效果如图所示:
我们来看该程序的主布局文件main.xml:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 添加一个居中显示的文本视图textView1 --> <TextView android:text="您正在学习RelativeLayout的用法 ,是否开始动手练习?" android:id="@+id/textView1" android:textSize="24px" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_centerInParent="true"/><!-- 添加一个在button2左侧显示的按钮button1 --> <Button android:text="开始练习" android:id="@+id/button1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/textView1" android:layout_toLeftOf="@+id/button2" /> <!-- 添加一个按钮button2,该按钮与textView1的右边界对齐 --> <Button android:text="不练习" android:id="@+id/button2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignRight="@+id/textView1" android:layout_below="@+id/textView1" /> </RelativeLayout>
通过这个例子,我们可以理解相对布局控件RelativeLayout的用法了。
- Android应用开发学习笔记之相对布局
- kshon学习笔记之android相对布局
- 【Android开发学习25】界面布局之相对布局RelativeLayout
- Android应用开发之RelativeLayout (相对布局)+梅花效果案例
- 相对布局(作业)-- MarsChen Android 开发教程学习笔记
- Android应用开发学习笔记之表格布局
- Android应用开发学习笔记之帧布局
- Android学习笔记之RelativeLayout(相对布局)
- 黑马程序员:Android学习笔记之RelativeLayout(相对)布局
- Android学习笔记之RelativeLayout(相对布局)
- Android学习笔记十四之RelativeLayout相对布局
- Android学习笔记十四之RelativeLayout相对布局
- Android学习-五布局之相对布局
- Android学习笔记08:相对布局RelativeLayout
- Android学习笔记(14):相对布局RelativeLayout
- android开发------编写用户界面之相对布局
- android开发------编写用户界面之相对布局
- android开发之-相对布局的属性
- 数据持久化之sharedpreference的使用
- eclipse 工具中关联 tomcat 源代码
- C# 数据库操作通用代码段
- js 判断svg插件(adobe viewer)
- ecshop购物车重登陆不丢失数据
- Android应用开发学习笔记之相对布局
- BOM相关性维护
- hdu1556 Color the ball
- PB学习笔记(一)
- android中phonegap下js调用java代码 progressbar显示的控制
- 武器库
- mysql 编码方式设置
- SecureCRT
- 学习线段树的一点心得