RelativeLayout

是相对布局在页面上相对于页面坐标进行布局设置。比如可以通过确定对象A确定对象B的位置,B可以在A的上下左右,对象B距离A的位置。

RelativeLayout的灵活性很高,但在实际操作过程中我很难确定定位对象的位置,最后用图形界面手托才完成页面的布局。

页面截图如下

实现代码如下

[java] view plaincopy

  1. <?xml version="1.0" encoding="utf-8"?>

  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

  3. android:layout_width="match_parent"

  4. android:layout_height="match_parent" >

  5. <TextView

  6. android:id="@+id/userName"

  7. android:layout_width="wrap_content"

  8. android:layout_height="wrap_content"

  9. android:layout_alignBottom="@+id/tipUserName"

  10. android:layout_alignParentTop="true"

  11. android:text="@string/user_name"

  12. android:textSize="20sp" />

  13. <EditText

  14. android:id="@+id/tipUserName"

  15. android:layout_width="match_parent"

  16. android:layout_height="wrap_content"

  17. android:layout_toRightOf="@id/userName"

  18. android:inputType="text"

  19. android:text="@string/tip_user_name" />

  20. <TextView

  21. android:id="@+id/passWord"

  22. android:layout_width="wrap_content"

  23. android:layout_height="wrap_content"

  24. android:layout_above="@+id/checkBox"

  25. android:layout_alignParentLeft="true"

  26. android:layout_below="@id/userName"

  27. android:layout_toLeftOf="@+id/tipUserName"

  28. android:text="@string/user_password"

  29. android:textSize="20sp" />

  30. <EditText

  31. android:id="@+id/tipPassword"

  32. android:layout_width="match_parent"

  33. android:layout_height="wrap_content"

  34. android:layout_below="@id/tipUserName"

  35. android:layout_toRightOf="@id/passWord"

  36. android:inputType="textPassword"

  37. android:text="@string/tip_user_password" />

  38. <Button

  39. android:id="@+id/logInBtn"

  40. android:layout_width="wrap_content"

  41. android:layout_height="wrap_content"

  42. android:layout_below="@id/passWord"

  43. android:text="@string/login_Btn" />

  44. <CheckBox

  45. android:id="@+id/checkBox"

  46. android:layout_width="match_parent"

  47. android:layout_height="wrap_content"

  48. android:layout_below="@id/tipPassword"

  49. android:layout_toRightOf="@id/logInBtn"

  50. android:text="@string/rember_pass" />

  51. </RelativeLayout>

用户名和密码字体过小,可用android:textSize="XXsp"调整字体大小。

我本来想通过用户名框的位置定下用户名输入框的位置和密码框的位置,再通过密码框的位置定位到密码输入框的和登陆按钮的位置,最后通过登陆按钮来确定单选框的位置。最后结果就是由于用户名框和密码框太小,导致部分挤在了一起,特别难看。

LinearLayout

线性布局也是一种比较灵活的布局方式, 通过直接的线性布局对页面直接实现布局。

在使用LinearLayout 的时候,思路大致是将页面母板分成若干部分,然后母板LinearLayout 使用android:orientation="vertical"将各个部分垂直分布,然后每个部分中的各个对象通过android:orientation="horizontal"实现各个对象的横向分布。

实现页面如下

实现代码如下

[java] view plaincopy

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

  2. xmlns:tools="http://schemas.android.com/tools"

  3. android:layout_width="match_parent"

  4. android:layout_height="match_parent"

  5. android:orientation="vertical"

  6. tools:context="${packageName}.${activityClass}"

  7. tools:ignore="Orientation" >

  8. <LinearLayout

  9. android:layout_width="match_parent"

  10. android:layout_height="wrap_content"

  11. android:orientation="horizontal" >

  12. <TextView

  13. android:id="@+id/userName"

  14. android:layout_width="wrap_content"

  15. android:layout_height="wrap_content"

  16. android:text="@string/user_name" />

  17. <EditText

  18. android:id="@+id/tipUserName"

  19. android:layout_width="0dp"

  20. android:layout_height="wrap_content"

  21. android:layout_weight="1"

  22. android:inputType="text"

  23. android:text="@string/tip_user_name" />

  24. </LinearLayout>

  25. <LinearLayout

  26. android:layout_width="match_parent"

  27. android:layout_height="wrap_content"

  28. android:orientation="horizontal" >

  29. <TextView

  30. android:id="@+id/passWord"

  31. android:layout_width="wrap_content"

  32. android:layout_height="wrap_content"

  33. android:text="@string/user_password" />

  34. <EditText

  35. android:id="@+id/tipPassword"

  36. android:layout_width="0dp"

  37. android:layout_height="wrap_content"

  38. android:layout_weight="1"

  39. android:inputType="textPassword"

  40. android:text="@string/tip_user_password" />

  41. </LinearLayout>

  42. <LinearLayout

  43. android:layout_width="match_parent"

  44. android:layout_height="wrap_content"

  45. android:orientation="horizontal" >

  46. <Button

  47. android:id="@+id/logInBtn"

  48. android:layout_width="wrap_content"

  49. android:layout_height="wrap_content"

  50. android:text="@string/login_Btn" />

  51. <CheckBox

  52. android:id="@+id/checkBox"

  53. android:layout_width="wrap_content"

  54. android:layout_height="wrap_content"

  55. android:text="@string/rember_pass" />

  56. </LinearLayout>

  57. </LinearLayout>

在使用LinearLayout 的时候要注意将各个对象包裹进 LinearLayout 。已经有了母板LinearLayout 就不用再重行创建LinearLayout 面板了。对于LinearLayout 的实现思路还是挺清晰的,所以部署起来还是不算很难。

转载于:https://my.oschina.net/253563059/blog/390522

RelativeLayout和LinearLayout的比较相关推荐

  1. 【转】RelativeLayout和LinearLayout及FrameLayout性能分析

    原文:http://blog.csdn.net/hejjunlin/article/details/51159419 工作一段时间后,经常会被领导说,你这个进入速度太慢了,竞品的进入速度很快,你搞下优 ...

  2. Android RelativeLayout和LinearLayout性能分析

    今天,简单讲讲android里RelativeLayout和LinearLayout的性能比较. 之前,我看到代码优化时需要将界面扁平化,所以查询了如何优化解码,了解一下RelativeLayout和 ...

  3. RelativeLayout和LinearLayout性能比较

    RelativeLayout和LinearLayout性能比较 相对布局和线性布局的性能比较 [转载请注明出处] :http://blog.csdn.net/guyuealian/article/de ...

  4. Android中常见五种布局管理器——RelativeLayout、LinearLayout、FrameLayout、TableLayout、GridLayout

    目录 布局管理器 RelativeLayout 常见属性 Relative的实践操作(实现软件更新界面) LinearLayout 常见属性 LinearLayout的实践操作(模范登录以及微信底部) ...

  5. LinearLayout和RelativeLayout属性和性能详解

    一.前期基础知识储备 上,官方文档 由上面的官方文档,我们可以看出,两个布局方式的相同,都是继承自View.Group,是一种容器控件,LinearLayout的布局层次比较简单,方向和位置都比较容易 ...

  6. 对Android 开发者有益的 40 条优化建议(转)

    下面是开始Android编程的好方法: 找一些与你想做事情类似的代码 调整它,尝试让它做你像做的事情 经历问题 使用StackOverflow解决问题 对每个你像添加的特征重复上述过程.这种方法能够激 ...

  7. Android开发常用属性

    1.android string.xml 文字中间加入空格 android string.xml前后加空格的技巧 <string name="password">密   ...

  8. 从Android界面开发谈起(转)

    原文地址:http://blog.csdn.net/nieweilin/article/details/5967815 这篇文章没有打算有一个很好的逻辑去介绍android的某个方面,全盘大致上就是我 ...

  9. 编写一个关于小型界面文件。

    首先遇到的是关于界面的问题,整体布局基本结束,可就是在RelativeLayout和linearLayout之间徘徊和争论. 因为按照预定的思维,使用RelativeLayout可以很好的完成整体的布 ...

最新文章

  1. java递归获取文件名_递归打印文件名
  2. ADO.NET 【属性扩展】性别、年龄、编号
  3. 九度OJ 1028:继续畅通工程 (最小生成树)
  4. Redis-学习笔记02【Redis命令操作】
  5. linux系统编程:自己动手写一个who命令
  6. php 匹配双字节字符串,收集一些常用的正则表达式(匹配中文字符、匹配双字节字符、匹配HTML标记、匹配空行 and so on~~~)...
  7. Java入门之窗口,精细全方位讲解,快乐学java铁铁们!
  8. C语言练习,求x的y次方的代码
  9. 【detectron】FPN网络输入
  10. C# 简单实现QQ截图功能
  11. 政务大数据的上下文范围
  12. 路在脚下,梦就在前方
  13. 最保险的“跳槽理由”
  14. 视频分享 500 G JAVA视频网盘分享(JEECG开源社区)
  15. python打开paint并画一个圆
  16. C/C++的内存分配?栈和堆的区别?为什么栈快?
  17. 9.Excel vba开发-转换为大写
  18. word press html,wordpress广告插件24款 管理网站广告代码很方便
  19. 【项目实战】Java从单体到微服务打造房产销售平台(一) - 整体概述
  20. 解决 hsdb jinfo jmap sa-jdi等mac不可用问题

热门文章

  1. 【UI设计】UI参考网站
  2. Excel逻辑函数:如何实现Excel条件智能标记,简单方法,速学!
  3. dw上传服务器显示文件错误,dw服务器配置错误
  4. 计算圆环面积的c语言程序,C0610求圆环面积_C语言程序设计源代码_doc_大学课件预览_高等教育资讯网...
  5. 简单表单提交php教程,php教程之表单提交实例_PHP教程
  6. 对口升学计算机网络网络试题,中职对口升学计算机网络检测试题一
  7. vscode 调试 typescript
  8. Chapter 12 贝叶斯网络
  9. c语言 update函数,feupdateenv
  10. 数据源——信用评分的前世今生【附FICO分介绍】