RelativeLayout和LinearLayout的比较
RelativeLayout
是相对布局在页面上相对于页面坐标进行布局设置。比如可以通过确定对象A确定对象B的位置,B可以在A的上下左右,对象B距离A的位置。
RelativeLayout的灵活性很高,但在实际操作过程中我很难确定定位对象的位置,最后用图形界面手托才完成页面的布局。
页面截图如下
实现代码如下
[java] view plaincopy
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/tipUserName"
android:layout_alignParentTop="true"
android:text="@string/user_name"
android:textSize="20sp" />
<EditText
android:id="@+id/tipUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/userName"
android:inputType="text"
android:text="@string/tip_user_name" />
<TextView
android:id="@+id/passWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/checkBox"
android:layout_alignParentLeft="true"
android:layout_below="@id/userName"
android:layout_toLeftOf="@+id/tipUserName"
android:text="@string/user_password"
android:textSize="20sp" />
<EditText
android:id="@+id/tipPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tipUserName"
android:layout_toRightOf="@id/passWord"
android:inputType="textPassword"
android:text="@string/tip_user_password" />
<Button
android:id="@+id/logInBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/passWord"
android:text="@string/login_Btn" />
<CheckBox
android:id="@+id/checkBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tipPassword"
android:layout_toRightOf="@id/logInBtn"
android:text="@string/rember_pass" />
</RelativeLayout>
用户名和密码字体过小,可用android:textSize="XXsp"调整字体大小。
我本来想通过用户名框的位置定下用户名输入框的位置和密码框的位置,再通过密码框的位置定位到密码输入框的和登陆按钮的位置,最后通过登陆按钮来确定单选框的位置。最后结果就是由于用户名框和密码框太小,导致部分挤在了一起,特别难看。
LinearLayout
线性布局也是一种比较灵活的布局方式, 通过直接的线性布局对页面直接实现布局。
在使用LinearLayout 的时候,思路大致是将页面母板分成若干部分,然后母板LinearLayout 使用android:orientation="vertical"将各个部分垂直分布,然后每个部分中的各个对象通过android:orientation="horizontal"实现各个对象的横向分布。
实现页面如下
实现代码如下
[java] view plaincopy
<LinearLayout 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"
android:orientation="vertical"
tools:context="${packageName}.${activityClass}"
tools:ignore="Orientation" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/user_name" />
<EditText
android:id="@+id/tipUserName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="text"
android:text="@string/tip_user_name" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/passWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/user_password" />
<EditText
android:id="@+id/tipPassword"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textPassword"
android:text="@string/tip_user_password" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/logInBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/login_Btn" />
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rember_pass" />
</LinearLayout>
</LinearLayout>
在使用LinearLayout 的时候要注意将各个对象包裹进 LinearLayout 。已经有了母板LinearLayout 就不用再重行创建LinearLayout 面板了。对于LinearLayout 的实现思路还是挺清晰的,所以部署起来还是不算很难。
转载于:https://my.oschina.net/253563059/blog/390522
RelativeLayout和LinearLayout的比较相关推荐
- 【转】RelativeLayout和LinearLayout及FrameLayout性能分析
原文:http://blog.csdn.net/hejjunlin/article/details/51159419 工作一段时间后,经常会被领导说,你这个进入速度太慢了,竞品的进入速度很快,你搞下优 ...
- Android RelativeLayout和LinearLayout性能分析
今天,简单讲讲android里RelativeLayout和LinearLayout的性能比较. 之前,我看到代码优化时需要将界面扁平化,所以查询了如何优化解码,了解一下RelativeLayout和 ...
- RelativeLayout和LinearLayout性能比较
RelativeLayout和LinearLayout性能比较 相对布局和线性布局的性能比较 [转载请注明出处] :http://blog.csdn.net/guyuealian/article/de ...
- Android中常见五种布局管理器——RelativeLayout、LinearLayout、FrameLayout、TableLayout、GridLayout
目录 布局管理器 RelativeLayout 常见属性 Relative的实践操作(实现软件更新界面) LinearLayout 常见属性 LinearLayout的实践操作(模范登录以及微信底部) ...
- LinearLayout和RelativeLayout属性和性能详解
一.前期基础知识储备 上,官方文档 由上面的官方文档,我们可以看出,两个布局方式的相同,都是继承自View.Group,是一种容器控件,LinearLayout的布局层次比较简单,方向和位置都比较容易 ...
- 对Android 开发者有益的 40 条优化建议(转)
下面是开始Android编程的好方法: 找一些与你想做事情类似的代码 调整它,尝试让它做你像做的事情 经历问题 使用StackOverflow解决问题 对每个你像添加的特征重复上述过程.这种方法能够激 ...
- Android开发常用属性
1.android string.xml 文字中间加入空格 android string.xml前后加空格的技巧 <string name="password">密 ...
- 从Android界面开发谈起(转)
原文地址:http://blog.csdn.net/nieweilin/article/details/5967815 这篇文章没有打算有一个很好的逻辑去介绍android的某个方面,全盘大致上就是我 ...
- 编写一个关于小型界面文件。
首先遇到的是关于界面的问题,整体布局基本结束,可就是在RelativeLayout和linearLayout之间徘徊和争论. 因为按照预定的思维,使用RelativeLayout可以很好的完成整体的布 ...
最新文章
- java递归获取文件名_递归打印文件名
- ADO.NET 【属性扩展】性别、年龄、编号
- 九度OJ 1028:继续畅通工程 (最小生成树)
- Redis-学习笔记02【Redis命令操作】
- linux系统编程:自己动手写一个who命令
- php 匹配双字节字符串,收集一些常用的正则表达式(匹配中文字符、匹配双字节字符、匹配HTML标记、匹配空行 and so on~~~)...
- Java入门之窗口,精细全方位讲解,快乐学java铁铁们!
- C语言练习,求x的y次方的代码
- 【detectron】FPN网络输入
- C# 简单实现QQ截图功能
- 政务大数据的上下文范围
- 路在脚下,梦就在前方
- 最保险的“跳槽理由”
- 视频分享 500 G JAVA视频网盘分享(JEECG开源社区)
- python打开paint并画一个圆
- C/C++的内存分配?栈和堆的区别?为什么栈快?
- 9.Excel vba开发-转换为大写
- word press html,wordpress广告插件24款 管理网站广告代码很方便
- 【项目实战】Java从单体到微服务打造房产销售平台(一) - 整体概述
- 解决 hsdb jinfo jmap sa-jdi等mac不可用问题
热门文章
- 【UI设计】UI参考网站
- Excel逻辑函数:如何实现Excel条件智能标记,简单方法,速学!
- dw上传服务器显示文件错误,dw服务器配置错误
- 计算圆环面积的c语言程序,C0610求圆环面积_C语言程序设计源代码_doc_大学课件预览_高等教育资讯网...
- 简单表单提交php教程,php教程之表单提交实例_PHP教程
- 对口升学计算机网络网络试题,中职对口升学计算机网络检测试题一
- vscode 调试 typescript
- Chapter 12 贝叶斯网络
- c语言 update函数,feupdateenv
- 数据源——信用评分的前世今生【附FICO分介绍】