RelativeLayout与LinearLayout的比较

Android中常见五种布局管理器——RelativeLayout、LinearLayout、FrameLayout、TableLayout、GridLayout 布局管理器 Android提供五种布局管理器: 1.相对布局管理器(RelativeLayout):通过相对定位的方式来控制组件的摆放位置。 2.线性布局管理器(LinearLayout):是指在水平或者垂直方向上依次摆放组件。 3.帧布局管理器(FrameLayout):没有任何定位方式,默认情况下,所有的组件都会摆放在容器的左上角,逐个覆盖。 4.表格布局管理器(TableLayout):使用表格的方式按行、列来摆放组件。 5.绝对布局管理器(AbsoluteLayout):通过绝对定位(x 阅读详情

RelativeLayout

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

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

页面截图如下


实现代码如下

  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.   
  6.     <TextView  
  7.         android:id="@+id/userName"  
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:layout_alignBottom="@+id/tipUserName"  
  11.         android:layout_alignParentTop="true"  
  12.         android:text="@string/user_name"  
  13.         android:textSize="20sp" />  
  14.   
  15.     <EditText  
  16.         android:id="@+id/tipUserName"  
  17.         android:layout_width="match_parent"  
  18.         android:layout_height="wrap_content"  
  19.         android:layout_toRightOf="@id/userName"  
  20.         android:inputType="text"  
  21.         android:text="@string/tip_user_name" />  
  22.   
  23.     <TextView  
  24.         android:id="@+id/passWord"  
  25.         android:layout_width="wrap_content"  
  26.         android:layout_height="wrap_content"  
  27.         android:layout_above="@+id/checkBox"  
  28.         android:layout_alignParentLeft="true"  
  29.         android:layout_below="@id/userName"  
  30.         android:layout_toLeftOf="@+id/tipUserName"  
  31.         android:text="@string/user_password"  
  32.         android:textSize="20sp" />  
  33.   
  34.     <EditText  
  35.         android:id="@+id/tipPassword"  
  36.         android:layout_width="match_parent"  
  37.         android:layout_height="wrap_content"  
  38.         android:layout_below="@id/tipUserName"  
  39.         android:layout_toRightOf="@id/passWord"  
  40.         android:inputType="textPassword"  
  41.         android:text="@string/tip_user_password" />  
  42.   
  43.     <Button  
  44.         android:id="@+id/logInBtn"  
  45.         android:layout_width="wrap_content"  
  46.         android:layout_height="wrap_content"  
  47.         android:layout_below="@id/passWord"  
  48.         android:text="@string/login_Btn" />  
  49.   
  50.     <CheckBox  
  51.         android:id="@+id/checkBox"  
  52.         android:layout_width="match_parent"  
  53.         android:layout_height="wrap_content"  
  54.         android:layout_below="@id/tipPassword"  
  55.         android:layout_toRightOf="@id/logInBtn"  
  56.         android:text="@string/rember_pass" />  
  57.   
  58. </RelativeLayout>  
<?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"实现各个对象的横向分布。

实现页面如下


实现代码如下

  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.   
  9.     <LinearLayout  
  10.         android:layout_width="match_parent"  
  11.         android:layout_height="wrap_content"  
  12.         android:orientation="horizontal" >  
  13.   
  14.         <TextView  
  15.             android:id="@+id/userName"  
  16.             android:layout_width="wrap_content"  
  17.             android:layout_height="wrap_content"  
  18.             android:text="@string/user_name" />  
  19.   
  20.         <EditText  
  21.             android:id="@+id/tipUserName"  
  22.             android:layout_width="0dp"  
  23.             android:layout_height="wrap_content"  
  24.             android:layout_weight="1"  
  25.             android:inputType="text"  
  26.             android:text="@string/tip_user_name" />  
  27.     </LinearLayout>  
  28.   
  29.     <LinearLayout  
  30.         android:layout_width="match_parent"  
  31.         android:layout_height="wrap_content"  
  32.         android:orientation="horizontal" >  
  33.   
  34.         <TextView  
  35.             android:id="@+id/passWord"  
  36.             android:layout_width="wrap_content"  
  37.             android:layout_height="wrap_content"  
  38.             android:text="@string/user_password" />  
  39.   
  40.         <EditText  
  41.             android:id="@+id/tipPassword"  
  42.             android:layout_width="0dp"  
  43.             android:layout_height="wrap_content"  
  44.             android:layout_weight="1"  
  45.             android:inputType="textPassword"  
  46.             android:text="@string/tip_user_password" />  
  47.     </LinearLayout>  
  48.   
  49.     <LinearLayout  
  50.         android:layout_width="match_parent"  
  51.         android:layout_height="wrap_content"  
  52.         android:orientation="horizontal" >  
  53.   
  54.         <Button  
  55.             android:id="@+id/logInBtn"  
  56.             android:layout_width="wrap_content"  
  57.             android:layout_height="wrap_content"  
  58.             android:text="@string/login_Btn" />  
  59.   
  60.         <CheckBox  
  61.             android:id="@+id/checkBox"  
  62.             android:layout_width="wrap_content"  
  63.             android:layout_height="wrap_content"  
  64.             android:text="@string/rember_pass" />  
  65.     </LinearLayout>  
  66.   
  67. </LinearLayout>  
<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 的实现思路还是挺清晰的,所以部署起来还是不算很难。

电机系列(1) - foc最基本原理、clark变换 、park变换、附代码 什么是FOC? FOC(Field-Oriented Control),直译是磁场定向控制,也被称作矢量控制 (VC,Vector Control) ,是目前无刷直流电机(BLDC)和永磁同步电机(PMSM)高效控制的最优方法之一。FOC旨在通过精确地控制磁场大小与方向,使得电机的运动转矩平稳、噪声小、效率高,并且具有高速的动态响应。 简单来说就是,FOC是一种对无刷电机的驱动控制方法,它可以让我们对无刷电机进行 “像素级” 控制,实现很多传统电机控制方法所无法达到的效果。 因为所谓的“矢量控制”其实就是 阅读详情

相关推荐

高德地图可视化入门:零基础用Python+高德API打造你的第一个热力图

本文详细介绍了如何使用Python和高德地图API从零构建商业级热力图。通过环境配置、地理编码、数据清洗到最终可视化展示的全流程指南,帮助开发者快速掌握地图可视化技术,特别适合展示商圈人流、疫情热点等地理分布数据。

weixin_29053067的博客 304

Android学习笔记(六):常用布局--LinearLayout线性布局、RelativeLayout相对布局、GridLayout网格布局、ScrollView滚动视图

通过本章的学习,可以掌握三种常用的布局和一个滚动视图:LinearLayout线性布局、RelativeLayout相对布局、GridLayout网格布局、ScrollView滚动视图

CJ_study的博客 2332

Smart200 PLC实现Bool信号接通延时、关闭延时作用

解决Smart200 PLC时间继电器和脉冲扫描P或N不能重复使用的问题,用于Bool信号延时接通和延时关闭的作用,可调整时间基数

gk_121的博客 4318

LinearLayout和RelativeLayout属性和性能详解

一、前期基础知识储备上,官方文档   由上面的官方文档,我们可以看出,两个布局方式的相同,都是继承自View.Group,是一种容器控件,LinearLayout的布局层次比较简单,方向和位置都比较容易控制,而相对布局RelativeLayout 对于其内子控件提供了更加丰富的布局层次和布局位置。二、两者在属性上的异同点共有属性: java代码中通过btn1关联次控件 android:id="@+...

Chin_Style的博客 8954

STM32F103VET6实战:用W25Q64外部Flash实现Bootloader+Application双备份(含完整代码解析)

本文详细介绍了基于STM32F103VET6微控制器和W25Q64外部Flash实现Bootloader+Application双备份固件升级的完整方案。通过精心设计的Flash分区策略、可靠的Bootloader程序以及包含双重校验和自动回滚机制的升级流程,有效解决了远程升级过程中断电导致设备变砖的风险,确保了工业嵌入式系统的高可靠性与稳定性。

linux的博客 823

雷达系统仿真——非相参累积和相参累积检测

非相参累积和相参累积检测 在雷达回波检测中,在特殊情况下,才会根据单个脉冲来进行检测判决。通常,雷达会从每个目标接收几个到几百个成串脉冲,在做出判决之前,要先对脉冲串进行处理。对脉冲串进行处理的方法有5种: 相参累积(Coherent Integration); 非相参累积(Nocoherent Integration); 二进制累积; 累计检测; 反馈累积器。 1 非相参累积 也叫“检波后累积”,或者“视频累积”(Video Integration),比检波前累积更容易完成,因为不需要保存回波的相位。

little_soldier的专栏 1万+

Android常用布局总结之(LinearLayout、TableLayout、GridLayout、RelativeLayout)

LinearLayout 是一个视图组,用于使所有子视图在单个方向(垂直或水平)保持对齐。您可以使用 android:orientation 属性指定布局方向。 TableLayout继承了LinearLayout,增加了表格的属性元素。 GridLayout和TableLayout(表格布局)有点类似,不过比TableLayout更加灵活好用。 RelativeLayout 相对布局,可以相对父容器,也可以相对兄弟组件。

不积跬步无以至千里,不积小流无以成江海。一个喜欢学习分享的程序员 3488

VHDL六层电梯控制器及仿真

六层电梯电梯 设计要求:设计一个六层电梯控制系统要求有超载、关门中断、提前关门清除报警信电梯外人的上升请求信号,电梯外人的下降请求信号, 电梯外人上升请求信号显示电梯外人下降请求信号显示到达楼层信号 设计思路:输入有clk时钟信号(频率为2Hz) full,deng,quick,clr超载、关门中断、提前关门清除报警c_u1,c_u2,c_u3,c_u4,c_u5电梯外人的上升请求c_d2,c_d3,c_d4,c_d5,c_d6 电梯外人的下降请求 d1,d2,d3,d4,d5,d6电梯内人的...

QQ_778132974的博客 1709

RelativeLayout和LinearLayout性能比较

相对布局和线性布局的性能比较 RelativeLayout和LinearLayout是Android中常用的布局,两者的使用会极大的影响程序生成每一帧的性能,因此,正确的使用它们是提升程序性能的重要工作 (1)RelativeLayout会让子View调用2次onMeasure,LinearLayout 在有weight时,也会调用子View 2次onMeasure (2)RelativeLayout的子View如果高度和RelativeLayout不同,则会引发效率问题,当子View很复杂时,这个问题会更

AI吃大瓜的博客 1万+

微信H5网页支付JSAPI部分用户报错:system:access_denied 的解决方案

JSAPI 支付仅支持微信内置浏览器调用。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 1685

【大模型+知识图谱】大模型与知识图谱融合:技术演进、实践应用与未来挑战

大模型与知识图谱的融合不是简单拼接,而是认知智能的范式重构。当符号主义的精确性与连接主义的泛化能力深度交织,我们正站在通向可信AGI的关键路口。正如OpenKG技术委员会王昊奋教授所言:“2025年将是图模协同从技术探索走向规模落地的分水岭”。参考文献OpenKG 2024年度报告(同济大学王昊奋)大型语言模型与知识图谱协同研究综述(海豚实验室,2024)知识图谱与大模型结合方法概述(黄巍,2023)图模互补:知识图谱与大模型融合综述(优快云,2024)

知识靠谱的博客 1090

RelativeLayout和LinearLayout的比较

RelativeLayout 是相对布局在页面上相对于页面坐标进行布局设置。比如可以通过确定对象A确定对象B的位置,B可以在A的上下左右,对象B距离A的位置。 RelativeLayout的灵活性很高,但在实际操作过程中我很难确定定位对象的位置,最后用图形界面手托才完成页面的布局。 页面...

chuogetai9128的博客 130

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

LinearLayout和RelativeLayout 比较

LinearLayout和RelativeLayout共有属性:java代码中通过btn1关联次控件android:id="@+id/btn1"控件宽度android:layout_width="80px" //"80dip"或"80dp"android:layout_wi

w176236767,做最好的程序员! 7315

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

RelativeLayout和LinearLayout性能比较 相对布局和线性布局的性能比较

【转载请注明出处】 http://blog.youkuaiyun.com/guyuealian/article/details/5216277  http://blog.youkuaiyun.com/guyuealian/article/details/5216277 转载请注明出处:http://blog.youkuaiyun.com/guyuealian/article/details/5216277看到几

innerwork的博客 632

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

LinearLayout和RelativeLayout的比较

LinearLayout和RelativeLayout 共有属性: java代码中通过btn1关联次控件 android:id="@+id/btn1" 控件宽度 android:layout_width="80px" //"80dip"或"80dp" android:layout_width =“wrap_content” android:layout_width =“mat

ruan200885的专栏 395

RelativeLayout 和LinearLayout比较小tip

为什么80%的码农都做不了架构师?>>> ...

weixin_33696822的博客 92
上一篇: Android总结之drawable(hdpi,mdpi,ldpi)文件夹的使用
下一篇: JAVA中int、String的类型转换
BeBeMo
博客等级 码龄14年 2粉丝 7原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值