Android-布局管理器

2023-11-09

线性布局(Linearlayout)

属性

orientation  布局管理器内组件的排列方式(horizontal(水平)和vertical(垂直),默认值为                 horizontal.)

layout_weight   权重  à  用于设置组件占父容器剩余空间的比例

layout_backgound 背景颜色

layout_gravity  设置当前组件在布局管理器中的位置

示例

代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <Button 
        android:id="@+id/tv_bt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt1"
        android:layout_weight="2"
		 />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:background="#90f0"
        android:layout_weight="2"    
        >
    <Button 
        android:id="@+id/tv_bt4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt4"
        android:layout_gravity="center"
		 />    
    <Button 
        android:id="@+id/tv_bt5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt5"
        android:layout_weight="2"
		android:layout_gravity="right|bottom"        
		 />                
    </LinearLayout>
    
    <Button 
        android:id="@+id/tv_bt2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt2"
		 />    
    <Button 
        android:id="@+id/tv_bt3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt3"
        android:layout_weight="1"
        
		 />
</LinearLayout>

显示

相对布局(RelativeLayout)

需要设置id属性

因为相对布局需要以其它控件(id)或父容器作为参照, 后放入控件的位置依赖于先放入的控件。

属性

控件属性

功能描述

android:layout_centerInParent

设置当前控件位于父布局的中央位置,

其属性值为boolean值

android:layout_centerVertical

设置当前控件位于父布局的垂直居中位置,

其属性值为boolean值

android:layout_centerHorizontal

设置当前控件位于父控件的水平居中位置

其属性值为boolean值

android:layout_above

设置当前控件位于某控件上方,

其属性值为其他UI组件的id属性

android:layout_below

设置当前控件位于某控件下方

其属性值为其他UI组件的id属性

android:layout_toLeftOf

设置当前控件位于某控件左侧

其属性值为其他UI组件的id属性

android:layout_toRightOf

设置当前控件位于某控件右侧

其属性值为其他UI组件的id属性

android:layout_alignParentTop

设置当前控件停靠于布局顶端

其属性值为boolean值

android:layout_alignParentLeft

设置当前控件停靠于布局左侧

其属性值为boolean值

android:layout_alignParentRight

设置当前控件停靠于布局右侧

其属性值为boolean值

android:layout_alignParentBottom

设置当前控件停靠于布局底端

其属性值为boolean值

                                              

                                                        设置当前控件的上边界与某控件的上边界对齐

android:layout_alignTop

设置当前控件的上边界与某控件的上边界对齐,

其属性值为其他UI组件的id属性

android:layout_alignBottom

设置当前控件的下边界与某控件的下边界对齐

其属性值为其他UI组件的id属性

android:layout_alignLeft

设置当前控件的左边界与某控件的左边界对齐

其属性值为其他UI组件的id属性

android:layout_alignRight

设置当前控件的右边界与某控件的右边界对齐

其属性值为其他UI组件的id属性

                                                           

                                                                设置当前控件边界与某控件的距离

android:layout_marginTop

设置当前控件上边界与某控件的距离

android:layout_marginBottom

设置当前控件底边界与某控件的距离

android:layout_marginLeft

设置当前控件左边界与某控件的距离

android:layout_marginRight

设置当前控件右边界与某控件的距离

 

示例

<?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" >
    
    
    <Button 
        android:id="@+id/bt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt1"
        />
    <Button 
        android:id="@+id/bt2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="bt2"
        />
    <Button 
        android:id="@+id/bt3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="bt3"
        />
    <Button 
        android:id="@+id/bt4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:text="bt4"
        />
    <Button 
        android:id="@+id/bt5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="bt5"
        />
    <Button 
        android:id="@+id/bt6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"        
        android:text="bt6"
        />
    <Button 
        android:id="@+id/bt7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="bt7"
        />
    <Button 
        android:id="@+id/bt8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="bt8"
        />

    <Button 
        android:id="@+id/bt9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="bt9"
        />
    <Button 
        android:id="@+id/bt10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/bt1"
        android:layout_toRightOf="@id/bt4"
        android:layout_above="@id/bt4"
        android:layout_alignRight="@id/bt2"
        android:text="bt10"
        />
    <Button 
        android:id="@+id/bt11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/bt10"
        android:layout_above="@id/bt7"
        android:layout_toRightOf="@id/bt4"
        android:text="bt11"
        />
    <Button 
        android:id="@+id/bt12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@id/bt5"
        android:layout_below="@id/bt5"
        android:layout_toLeftOf="@id/bt6"
        android:layout_alignBaseline="@id/bt11"
        android:text="bt12"
        />
    
    

</RelativeLayout>

表格布局(Tablelayout)

表格布局属性

控件属性

功能描述

android:layout_column

设置该单元显示位置

android:layout_span

设置该单元格占据几行,默认为1

 表格布局中控件属性

控件属性

功能描述

android:layout_column

设置该单元显示位置

android:layout_span

设置该单元格占据几行,默认为1

示例

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="1,2" >
    
    <TableRow 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="点a:"/>
        
        <EditText 
            android:id="@+id/et_ax"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="x"/>
            
        <EditText 
            android:id="@+id/et_ax"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="y"/>
        
    </TableRow>
    
     <TableRow 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="点b:"/>
        
        <EditText 
            android:id="@+id/et_bx"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="x"/>
            
        <EditText 
            android:id="@+id/et_bx"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="y"/>
        
    </TableRow>
    
     <Button 
         android:id="@+id/bt"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="确定"/>
     
     

</TableLayout>

帧布局(FrameLayout)

示例

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:foreground="@drawable/ic_launcher"   
    android:foregroundGravity="right|bottom" 
    >
    
    <TextView 
        android:layout_gravity="center"
        android:layout_width="400px"
        android:layout_height="400px"
        android:background="#f00"
        android:text="红色背景的TextView"/>
    
    <TextView 
        android:layout_gravity="center"
        android:layout_width="300px"
        android:layout_height="300px"
        android:background="#FF8000"
        android:text="橙色背景的TextView"/>
    
    <TextView 
        android:layout_gravity="center"
        android:layout_width="200px"
        android:layout_height="200px"
        android:background="#FFFF00"
        android:text="黄色背景的TextView"/>

</FrameLayout>

 网格布局(GridLayout)

 示例

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:columnCount="4"
    >
    
    <Button 
        android:id="@+id/bt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt1"
        android:layout_column="3"
        />
    <Button 
        android:id="@+id/bt2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt2"
        />
    <Button 
        android:id="@+id/bt3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt3"
        />
    <Button 
        android:id="@+id/bt4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt4"
        />
    <Button 
        android:id="@+id/bt5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt5"
        />
    <Button 
        android:id="@+id/bt6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt6"
        />
    <Button 
        android:id="@+id/bt7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt7"
        />
    <Button 
        android:id="@+id/bt8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt8"
        />
    <Button 
        android:id="@+id/bt9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt9"
        />
    <Button 
        android:id="@+id/bt10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt10"
        />
    <Button 
        android:id="@+id/bt11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt11"
        />
    <Button 
        android:id="@+id/bt12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt12"
        />
    
    <Space />
    <Button 
        android:id="@+id/bt13"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt13"
        android:layout_columnSpan="2"
        android:layout_gravity="fill_horizontal"
        />
    <Button 
        android:id="@+id/bt14"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt14"
        />
    <Button 
        android:id="@+id/bt15"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_rowSpan="2"
        android:layout_gravity="fill_vertical"
        android:text="bt15"

        />
    <Button 
        android:id="@+id/bt16"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_columnSpan="3"
        android:layout_gravity="fill_horizontal"
        android:text="bt16"
        />
    <Space />

</GridLayout>

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android-布局管理器 的相关文章

随机推荐

  • 如何解决 conda install 库时报错:The environment is inconsistent, please check the package plan carefully

    在使用conda 安装库时 遇到了这样的问题 无论怎么安装都无法解决上述问题 本着可能是源的问题以及哪一步安装版本的问题 调试了一通后 解决了安装库失败的问题 首先是恢复默认源 恢复默认源 conda config remove key c
  • 计算机环境变量怎么恢复默认,windows10系统中环境变量怎么恢复默认

    有不少windows10系统用户在设置环境变量之后 可能不小心被恶意修改了导致出现问题 那么我们只需要将环境变量恢复默认即可 那么该怎么操作呢 本文就给大家讲解一下windows10系统中环境变量恢复默认的具体步骤如下 组策略编辑器中的MM
  • 以太坊智能合约虚拟机(EVM)原理与实现

    以太坊 EVM原理与实现 以太坊底层通过EVM模块支持合约的执行与调用 调用时根据合约地址获取到代码 生成环境后载入到EVM中运行 通常智能合约的开发流程是用solidlity编写逻辑代码 再通过编译器编译元数据 最后再发布到以太坊上 代码
  • 2023最新STM32毕业设计项目集合

    文章目录 1前言 2 STM32 毕设课题 3 如何选题 3 1 不要给自己挖坑 3 2 难度把控 3 3 如何命名题目 4 最后 1前言 更新单片机嵌入式选题后 不少学弟学妹催学长更新STM32和C51选题系列 感谢大家的认可 来啦 以下
  • Shiro权限框架-限制密码重试次数(8)

    1 实现原理 保证原子性 单系统 AtomicLong计数 集群系统 RedissionClient提供的RAtomicLong计数 1 获取系统中是否已有登录次数缓存 缓存对象结构预期为 用户名 登录次数 2 如果之前没有登录缓存 则创建
  • 【ElementUI样式优化1】el-table 修改斑马格样式、修改滚动条样式、添加表头边框、删除表格边框划线

    重要的不是过去 而是你怎末看待过去 而我们对过去的看法 是可以改变的 效果预览 1 删除表格外框 内框 2 添加表头边框 修改表头文字大小 颜色 3 斑马格修改颜色 选中行高亮颜色修改 4 修改滚动条样式 目录 一 原始样式说明 1 斑马纹
  • 试用许可常见问题解析

    从安装许可驱动 到正确配置试用许可 大家可能会遇到的各种问题 本文针对各类问题逐一介绍以及使用产品过程中许可中心异常的解决办法 在SuperMap 7C及8C系列产品中 均使用是LicenseCenter来配置及管理所有产品的许可 在安装i
  • husky无法工作 commit 提交代码时husky不生效解决方法

    husky无法工作原因 新版本 husky 中存在严重错误 https github com typicode husky issues 326 解决方法 安装低版本即可 yarn remove husky yarn add husky 4
  • Linux:C语言实现面向接口编程

    在Linux环境下 实现面向接口编程可以使用C语言中的函数指针来实现 具体步骤如下 定义接口 定义一个接口 包含一组函数指针 这些函数指针代表了该接口的方法 例如 我们可以定义一个名为 Interface 的接口 cCopy code ty
  • flow对性能的影响

    不同高中低端ROUTER 其netflow处理性能果然相差很大低端10000f s是极限 中端40000f s 高端60000f s 且还有simpled这个杀手锏 低端ROUTER 2600 2800 3600 3700 来说 采集100
  • 使用Python爬取前程无忧上南京地区Python职位以及对应工资

    获取原始数据 最近在学习Python 做了一个爬虫程序练练手 前程无忧这个网站页面布局还是挺简单的 适合我这种新手 使用requests bs4爬取 不多说了 先来看看页面布局吧 这是前程无忧上的职位列表 看上去还是很清楚的 然后再来看看页
  • systemctl start network 启动网卡服务报错解决方法

    systemctl start network 启动网卡服务报错 root apache systemctl restart network Job for network service failed because the contro
  • Hibernate之查询中get()和load()的区别,list()和iterate()的区别

    Hibernate 之查询中get 和load 的区别 list 和iterate 的区别 list 查询 一次性把数据对象取出来 Test public void findTestList Session s sessionFactory
  • python3 面试题总结

    Python global 语句的作用 lambda 匿名函数好处 Python 错误处理 Python 内置错误类型 简述 any 和 all 方法 Python 中什么元素为假 提高 Python 运行效率的方法 Python 单例模式
  • LeetCode63. 不同路径 II

    不同路径 II 一个机器人位于一个 m x n 网格的左上角 起始点在下图中标记为 Start 机器人每次只能向下或者向右移动一步 机器人试图达到网格的右下角 在下图中标记为 Finish 现在考虑网格中有障碍物 那么从左上角到右下角将会有
  • Halcon三维模型预处理(1):调平的三大手法

    面结构光拍摄生成的点云模型 往往相对系统坐标系是有角度的 首先讲一下调平的目的 1 为接下来的预处理切除背景面做准备 3 不做调平 后续处理会很麻烦 因为不清楚坐标系在平台的为位置 2 对于无序抓取项目 平台相对相机可能是有角度的 将抓取平
  • socket和mongodb

    socket 创建一个socket 然后连接server url net Socket 发送信息给服务器 socket通信 client可以进行数据的编写和发送 服务器 只有一个 只有开启了服务器 客户端才能进行连接 mongodb 关系型
  • 归并排序(简单易懂的代码)

    归并排序是一种很重要的排序算法 体现的是分而治之的思想 很多的算法题的解法会借用这种算法思想 在这里使用C 编程实现归并排序 供自己回忆 供他人参考 include
  • 单元测试--重构

    一 单元测试 1 在没写函数内容代码前 就要写单元测试类 每个测试类中有TestSuite 2 如果写单元测试很困难 那么可能是你对要测试的函数不是很了解 如果不是则可能是设计的问题 也许要重构 二 重构1 不要存在代码重复的现象 若有 且
  • Android-布局管理器

    线性布局 Linearlayout 属性 orientation 布局管理器内组件的排列方式 horizontal 水平 和vertical 垂直 默认值为 horizontal layout weight 权重 用于设置组件占父容器剩余空