`
king_tt
  • 浏览: 2119575 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

【Android 开发教程】RelativeLayout相对布局

 
阅读更多

本章节翻译自《Beginning-Android-4-Application-Development》,如有翻译不当的地方,敬请指出。

原书购买地址http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/


使用RelativeLayout,可以通过设置“相对位置”(每个View相对于另一个view的位置),来指定它所包含的子view的位置。看下面main.xml中的代码:

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:id="@+id/RLayout"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent">
  6. <TextView
  7. android:id="@+id/lblComments"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:layout_alignParentLeft="true"
  11. android:layout_alignParentTop="true"
  12. android:text="Comments"/>
  13. <EditText
  14. android:id="@+id/txtComments"
  15. android:layout_width="fill_parent"
  16. android:layout_height="170px"
  17. android:layout_alignLeft="@+id/lblComments"
  18. android:layout_below="@+id/lblComments"
  19. android:layout_centerHorizontal="true"
  20. android:textSize="18sp"/>
  21. <Button
  22. android:id="@+id/btnSave"
  23. android:layout_width="125px"
  24. android:layout_height="wrap_content"
  25. android:layout_alignRight="@+id/txtComments"
  26. android:layout_below="@+id/txtComments"
  27. android:text="Save"/>
  28. <Button
  29. android:id="@+id/btnCancel"
  30. android:layout_width="124px"
  31. android:layout_height="wrap_content"
  32. android:layout_alignLeft="@+id/txtComments"
  33. android:layout_below="@+id/txtComments"
  34. android:text="Cancel"/>
  35. </RelativeLayout>
可以观察到,这些views都被嵌在了RelativeLayout里面,每个view都有一些特有的属性去和其他view对准位置。这些属性是:
  • layout_alignParentTop
  • layout_alignParentLeft
  • layout_alignRight
  • layout_below
  • layout_centerHorizontal

这些属性的值,就是每个被引用的view的id。

效果图:




分享到:
评论

相关推荐

    Android开发教程之Android 五大布局--千锋培训

    文档介绍了前言,FrameLayout布局,LinearLayout布局,RelativeLayout布局,TableLayout布局,AbsoluteLayout布局

    Android开发案例驱动教程 配套代码

    《Android开发案例驱动教程》 配套代码。 注: 由于第12,13,14章代码太大,无法上传到一个包中。 这三节代码会放到其他压缩包中。 作者:关东升,赵志荣 Java或C++程序员转变成为Android程序员 采用案例驱动模式...

    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图形接口的程序结构...

    传智播客Android视频教程-课程源码.rar

    LinearLayout (线性布局)、AbsoluteLayout(绝对布局)、RelativeLayout(相对布局)、TableLayout(表格布局)、FrameLayout(帧布局) 第二天 1&gt; 单元测试 2&gt; 查看与输出日志信息 3&gt; 文件操作 4&gt; 往SDCard读写文件 5&gt; ...

    Android简明应用程序开发[原创]

    二、RelativeLayout布局 44 三、LinearLayout布局 53 四、AbsoluteLayout布局 55 五、FrameLayout布局 56 六、TableLayout布局 61 七、小结 66 第四章 表单Widgets 67 一、基本类Widget 67 4.1.1 ...

    Android 应用开发入门教程(经典版)

    第2 章 Android SDK 的开发环境.................................................................................................................................. 10 2.1 Android SDK 的结构..................

    android开发教程之使用listview显示qq联系人列表

    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_...

    黎活明android教程的全程PPT

    LinearLayout (线性布局)、AbsoluteLayout(绝对布局)、RelativeLayout(相对布局)、TableLayout(表格布局)、FrameLayout(帧布局) 第二天 1&gt; 单元测试 2&gt; 查看与输出日志信息 3&gt; 文件操作 4&gt; 往SDCard读写文件 5&gt;...

    APP开发教程 Java Android移动端开发 3、Android UI编程(2) 共19页.pptx

    控件树其动态增删改查 用代码来生成界面 常用布局介绍 RelativeLayout FrameLayout

    Android应用开发入门教程(经典版)

    第2章 Android SDK的开发环境..................................................................................................................................10 2.1 Android SDK的结构......................

    Android实战教程第四十三篇之上拉加载与下拉刷新

    &lt;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&gt; &lt;me....

    Android自定义照相机倒计时拍照

    相关教程:Android开发从相机或相册获取图片裁剪 Android启动相机拍照并返回图片 &lt;RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=http://schemas.android.com/tools ...

    Android App开发中ViewPager组件的入门使用教程

    首先让大家有个全局的认识,直接上个项目,看看仅仅通过这几行代码,竟然就能完成如此强悍的功能。下篇再仔细讲讲为什么要...RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=h

    Android仿百度壁纸客户端之搭建主框架(一)

    这是个不错的教程,自己学完了之后就拿出来分享了,本来想一个帖子写完,但是发现这样对自己写博客的效率有点出入,为了让大家看的舒服点,所以分开来写,我们先开看下百度壁纸的客户端是什么样子的 我们先来写个...

Global site tag (gtag.js) - Google Analytics