本章节翻译自《Beginning-Android-4-Application-Development》,如有翻译不当的地方,敬请指出。
原书购买地址http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/
使用RelativeLayout,可以通过设置“相对位置”(每个View相对于另一个view的位置),来指定它所包含的子view的位置。看下面main.xml中的代码:
- <?xmlversion="1.0"encoding="utf-8"?>
- <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/RLayout"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <TextView
- android:id="@+id/lblComments"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:text="Comments"/>
- <EditText
- android:id="@+id/txtComments"
- android:layout_width="fill_parent"
- android:layout_height="170px"
- android:layout_alignLeft="@+id/lblComments"
- android:layout_below="@+id/lblComments"
- android:layout_centerHorizontal="true"
- android:textSize="18sp"/>
- <Button
- android:id="@+id/btnSave"
- android:layout_width="125px"
- android:layout_height="wrap_content"
- android:layout_alignRight="@+id/txtComments"
- android:layout_below="@+id/txtComments"
- android:text="Save"/>
- <Button
- android:id="@+id/btnCancel"
- android:layout_width="124px"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/txtComments"
- android:layout_below="@+id/txtComments"
- android:text="Cancel"/>
- </RelativeLayout>
可以观察到,这些views都被嵌在了RelativeLayout里面,每个view都有一些特有的属性去和其他view对准位置。这些属性是:
- layout_alignParentTop
- layout_alignParentLeft
- layout_alignRight
- layout_below
- layout_centerHorizontal
这些属性的值,就是每个被引用的view的id。
效果图:
分享到:
相关推荐
文档介绍了前言,FrameLayout布局,LinearLayout布局,RelativeLayout布局,TableLayout布局,AbsoluteLayout布局
《Android开发案例驱动教程》 配套代码。 注: 由于第12,13,14章代码太大,无法上传到一个包中。 这三节代码会放到其他压缩包中。 作者:关东升,赵志荣 Java或C++程序员转变成为Android程序员 采用案例驱动模式...
8.4.3.相对布局(RelativeLayout)101 8.4.4.表单布局(Table Layout)103 8.5 网格(Grid)视图组103 8.6 列表(List)视图组107 8.7 使用Tab组织UI109 第9章 2D图形接口的使用113 9.1 使用2D图形接口的程序结构...
LinearLayout (线性布局)、AbsoluteLayout(绝对布局)、RelativeLayout(相对布局)、TableLayout(表格布局)、FrameLayout(帧布局) 第二天 1> 单元测试 2> 查看与输出日志信息 3> 文件操作 4> 往SDCard读写文件 5> ...
二、RelativeLayout布局 44 三、LinearLayout布局 53 四、AbsoluteLayout布局 55 五、FrameLayout布局 56 六、TableLayout布局 61 七、小结 66 第四章 表单Widgets 67 一、基本类Widget 67 4.1.1 ...
第2 章 Android SDK 的开发环境.................................................................................................................................. 10 2.1 Android SDK 的结构..................
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_...
LinearLayout (线性布局)、AbsoluteLayout(绝对布局)、RelativeLayout(相对布局)、TableLayout(表格布局)、FrameLayout(帧布局) 第二天 1> 单元测试 2> 查看与输出日志信息 3> 文件操作 4> 往SDCard读写文件 5>...
控件树其动态增删改查 用代码来生成界面 常用布局介绍 RelativeLayout FrameLayout
第2章 Android SDK的开发环境..................................................................................................................................10 2.1 Android SDK的结构......................
<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> <me....
相关教程:Android开发从相机或相册获取图片裁剪 Android启动相机拍照并返回图片 <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=http://schemas.android.com/tools ...
首先让大家有个全局的认识,直接上个项目,看看仅仅通过这几行代码,竟然就能完成如此强悍的功能。下篇再仔细讲讲为什么要...RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=h
这是个不错的教程,自己学完了之后就拿出来分享了,本来想一个帖子写完,但是发现这样对自己写博客的效率有点出入,为了让大家看的舒服点,所以分开来写,我们先开看下百度壁纸的客户端是什么样子的 我们先来写个...