04 Android基础--RelativeLayout
04 Android基础--RelativeLayout
- 什么是RelativeLayout?
- RelativeLayout的常见用法:
什么是RelativeLayout?
相对布局(RelativeLayout)是一种根据
父容器
和兄弟控件
作为参照
来确定控件位置的布局方式。
根据父容器定位
在相对布局中,可以通过以下的属性让的组合让控件处于父容器左上角、右上角、左下角、右下角、上下左右居中,正居中
等九个位置。属性如下:
- android:layout_alignParentLeft=“true” 父容器左边
- android:layout_alignParentRight=“true” 父容器右边
- android:layout_alignParentTop=“true” 父容器顶部
- android:layout_alignParentBottom=“true” 父容器底部
- android:layout_centerHorizontal=“true” 水平方向居中
- android:layout_centerVertical=“true” 垂直方向居中
- android:layout_centerInParent=“true” 水平垂直都居中
根据兄弟控件定位
在相对布局中,还支持通过已确定位置的控件作为参考来确定其他控件的位置,以下的属性让的组合让控件处于另外控件左上角、右上角、左下角、右下角、正上方、正下方、正左方、正右方
等位置。属性如下:
- android:layout_toLeftOf=“@+id/button1” 在button1控件左方
- android:layout_toRightOf=“@+id/button1” 在button1控件右方
- android:layout_above=“@+id/button1” 在button1控件上方
- android:layout_below=“@+id/button1” 在button1控件下方
- android:layout_alignLeft=“@+id/button1” 与button1控件左边平齐
- android:layout_alignRight=“@+id/button1” 与button1控件右边平齐
- android:layout_alignTop=“@+id/button1” 与button1控件上边平齐
- android:layout_alignBottom=“@+id/button1” 与button1控件下边平齐
RelativeLayout的常见用法:
第一种情况:常用的列表页布局:
<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent">// 标题<includeandroid:id="@+id/title_layout"layout="@layout/title_layout"/>// 1.android:layout_below="@+id/title_layout";这个布局在title的下方// 2.android:layout_marginBottom="60dp";指定该属性所在控件距下部最近控件的最小值;<androidx.swiperefreshlayout.widget.SwipeRefreshLayoutandroid:id="@+id/sw_layout"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@+id/title_layout"android:layout_marginBottom="60dp"><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/recyclerview"android:layout_width="match_parent"android:layout_height="match_parent" /></androidx.swiperefreshlayout.widget.SwipeRefreshLayout>// 3.android:layout_alignParentBottom="true";在父容器底部<LinearLayoutandroid:layout_alignParentBottom="true"><Buttonandroid:id="@+id/material_apply"android:layout_width="match_parent"android:layout_height="match_parent"/></LinearLayout></RelativeLayout>
第二种情况:常用的搜索抽屉布局:
搜索栏有很多,有滚动条,重置与搜索按钮在最底部。
<RelativeLayout>// 1. 添加滚动条<androidx.core.widget.NestedScrollViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:paddingHorizontal="20dp">// 2. 搜索栏需要 占满全屏 <LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><TextViewstyle="@style/select_title"android:text="@string/material_type" /><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/madetails_recyclerview"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp" /><TextViewstyle="@style/select_title"android:layout_marginTop="20dp"android:text="@string/name_of_goods" /><EditTextandroid:id="@+id/madetails_name_of_goods"style="@style/select_ed"android:background="@drawable/select_ed_background"android:hint="@string/name_of_goods" /><TextViewstyle="@style/select_title"android:layout_marginTop="20dp"android:text="@string/model_of_goods" /><EditTextandroid:id="@+id/madetails_model_of_goods"style="@style/select_ed"android:background="@drawable/select_ed_background"android:hint="@string/model_of_goods" /><TextViewstyle="@style/select_title"android:layout_marginTop="20dp"android:text="@string/specification_of_goods" /><EditTextandroid:id="@+id/madetails_specification_of_goods"style="@style/select_ed"android:background="@drawable/select_ed_background"android:hint="@string/specification_of_goods" /><TextViewstyle="@style/select_title"android:layout_marginTop="20dp"android:text="@string/code_of_goods" /><EditTextandroid:id="@+id/madetails_code_of_goods"style="@style/select_ed"android:background="@drawable/select_ed_background"android:hint="@string/code_of_goods" /></LinearLayout></androidx.core.widget.NestedScrollView>// 3. android:layout_alignParentBottom="true";相对于根元素布局,在根元素的底部。<LinearLayoutstyle="@style/select_bottom_layout"android:layout_alignParentBottom="true"><Buttonandroid:id="@+id/reset_btn"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="2"android:background="@color/dark_blue"android:text="@string/reset"android:textColor="@color/white"android:textSize="22dp" /><Buttonandroid:id="@+id/filter_btn"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="3"android:background="@color/colorAccent"android:text="@string/filter"android:textColor="@color/white"android:textSize="22dp" /></LinearLayout></RelativeLayout>
类似于这种布局的做法:1.上面的元素需要
占满全屏
2.下面的按钮android:layout_alignParentBottom="true"
相对父元素布局,在父元素的底部。
第三种情况:子页面展示项
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical""><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><!--1. android:layout_alignParentLeft="true": 父容器左边android:layout_alignParentRight="true" 父容器右边android:layout_centerInParent="true" 水平垂直都居中--><RelativeLayout android:layout_width="match_parent"android:layout_height="60px"><TextViewandroid:layout_alignParentLeft="true"android:layout_centerInParent="true"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="测试" /><TextViewandroid:id="@+id/apply_form_tv"android:layout_alignParentRight="true"android:layout_centerInParent="true"android:layout_width="wrap_content"android:layout_height="wrap_content"tools:text="测试" /></RelativeLayout><!--测试--><RelativeLayout style="@style/sub_line"><TextViewandroid:layout_alignParentLeft="true"android:layout_centerInParent="true"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="测试" /><TextViewandroid:id="@+id/apply_form_tv"android:layout_alignParentRight="true"android:layout_centerInParent="true"android:layout_width="wrap_content"android:layout_height="wrap_content"tools:text="测试" /></RelativeLayout></LinearLayout></RelativeLayout>
对于这种展示形布局或者说是提交型布局:1.<LinearLayout 标签可以让其下的子布局页面竖向排列 2.<RelativeLayout 标签:位于父容器左边与父容器右边,且水平竖直居中。
相关文章:

04 Android基础--RelativeLayout
04 Android基础--RelativeLayout什么是RelativeLayout?RelativeLayout的常见用法:什么是RelativeLayout? 相对布局(RelativeLayout)是一种根据父容器和兄弟控件作为参照来确定控件位置的布局方式。 根据父容器定位 在相…...

python基础命令
1.现在包的安装路径 #pip show 包名 2.pip讲解 相信对于大多数熟悉Python的人来说,一定都听说并且使用过pip这个工具,但是对它的了解可能还不一定是非常的透彻,今天小编就来为大家介绍10个使用pip的小技巧,相信对大家以后管理和…...

用 Real-ESRGAN 拯救座机画质,自制高清版动漫资源
内容一览:Real-ESRGAN 是 ESRGAN 升级之作,主要有三点创新:提出高阶退化过程模拟实际图像退化,使用光谱归一化 U-Net 鉴别器增加鉴别器的能力,以及使用纯合成数据进行训练。 关键词:Real-ESRGAN 超分辨率 视…...
数据结构预备知识(模板)
模板 功能上类比C的重载函数,可以使用一种通用的形式,去代替诸多数据类型,使得使用同一种函数的时候,可以实现对于不同数据类型的相同操作。增强类和函数的可重用性。 使用模板函数为函数或类声明一个一般的模式,使得…...

SWM181按键控制双通道PWM固定占空比输出
SWM181按键控制双通道PWM固定占空比输出📌SDK固件包:https://www.synwit.cn/kuhanshu_amp_licheng/ 🌼开发板如下图: ✨注意新手谨慎选择作为入门单片机学习。目前只有一个简易的数据手册和SDK包,又没有参考手册&am…...
pygame函数命令
pygame.mixer.music.load() —— 载入一个音乐文件用于播放 pygame.mixer.music.play() —— 开始播放音乐流 pygame.mixer.music.rewind() —— 重新开始播放音乐 pygame.mixer.music.stop() —— 结束音乐播放 pygame.mixer.music.pause() —— 暂停音乐播放 pygame.mixer.mu…...

异步循环
业务 : 批量处理照片 , 批量拆建 , 裁剪一张照片需要异步执行等待 , 并且是批量 所以需要用到异步循环 裁剪图片异步代码 : 异步循环 循环可以是 普通 for 、 for of 、 for in 不能使用forEach ,这里推荐 for…...

Vue表单提交与数据存储
学习内容来源:视频p5 书接目录对页面重新命名选择组件后端对接测试接口设置接口前端调用对页面重新命名 将之前的 Page1 Page2 进行重新命名,使其具有实际意义 Page1 → BookManage ; Page2 → AddBook 并且 /router/index.js 中配置页面信息…...
API网关(接入层之上业务层之上)以及业务网关(后端服务网关)设计思路(二)
文章目录 流量网关业务网关常见网关对比1. OpenResty2. KongKong解决了什么问题Kong的优点以及性能Kong架构3. Zuul1.0过滤器IncomingEndpointOutgoing过滤器类型Zuul 1.0 请求生命周期4. Zuul2.0Zuul 与 Zuul 2 性能对比5. Spring Cloud GatewaySpring Cloud Gateway 底层使用…...

有些笑话,外行人根本看不懂,只有程序员看了会狂笑不止
我一直都觉得我们写代码的程序员与众不同,就连笑话都跟别人不一样。 如果让外行人来看我们一些我们觉得好笑的东西,他们根本不知道笑点在哪里。 不信你来瞧瞧,但凡有看不懂的地方,说明你的道行还不够深。 1.大多数人开始学编程时…...

企业电子招投标采购系统——功能模块功能描述
功能模块: 待办消息,招标公告,中标公告,信息发布 描述: 全过程数字化采购管理,打造从供应商管理到采购招投标、采购合同、采购执行的全过程数字化管理。通供应商门户具备内外协同的能力,为外…...

Presto 在美图的实践
导读:本文的主题是Presto高性能引擎在美图的实践,首先将介绍美图在处理ad-hoc场景下为何选择Presto,其次我们如何通过外部组件对Presto高可用与稳定性的增强。然后介绍在美图业务中如何做到合理与高效的利用集群资源,最后如何利用…...

Molecule:使用Jetpack Compose构建StateFlow流
Molecule:使用Jetpack Compose构建StateFlow流 看下面的jetpack compose片段: Composable fun MessageCard(message: Message) {Column {Text(text message.author)Text(text message.body)} }这段代码最有趣的部分是它实际上是reactive。其反应性为 通过Composa…...

计算机组成原理(2.2)--系统总线
目录 一、总线结构 1.单总线结构 1.1单总线结构框图 编辑1.2单总线性能下降的原因 2.多总线结构 2.1双总线结构 2.2三总线结构 2.3四总线结构 编辑 二、总线结构举例 1. 传统微型机总线结构 2. VL-BUS局部总线结构 3. PCI 总线结构 4. 多层 PCI 总线结构 …...

如何使用dlinject将一个代码库实时注入到Linux进程中
关于dlinject dlinject是一款针对Linux进程安全的注入测试工具,在该工具的帮助下,广大研究人员可以在不使用ptrace的情况下,轻松向正在运行的Linux进程中注入一个共享代码库(比如说任意代码)。之所以开发该工具&#…...

Docker安装Cassandra数据库,在SpringBoot中连接Cassandra
简介 Apache Cassandra是一个高度可扩展的高性能分布式数据库,旨在处理许多商用服务器上的大量数据,提供高可用性而没有单点故障。它是NoSQL数据库的一种。首先让我们了解一下NoSQL数据库的作用。 NoSQL 数据库 NoSQL数据库(有时称为“Not …...
Linux常用命令总结(建议收藏)
Linux常用命令总结(建议收藏) 这里收集了一些常用命令以便需要时查看,欢迎作补充。(这里的提到操作都默认以CentOS系统为基础) 文件管理 目录操作 切换目录 cd 查看目录 ls -l 列出文件详细信息 或者直接ll-a 列出当前目录下所有文件及…...

【Java】P1 基础知识与碎碎念
Java 基础知识 碎碎念安装 Intellij IDEAJDK 与 JREJava 运行过程Java 系统配置Java 运行过程Java的三大分类前言 本节内容主要围绕Java基础内容,从Java的安装到helloworld,什么是JDK与什么是JRE,系统环境配置,不深入Java代码知识…...

Jackson CVE-2017-7525 反序列化漏洞
0x00 前言 Jackson 相对应fastjson来说利用方面要求更加苛刻,默认情况下无法进行利用。 同样本次的调用链也可以参考fastjson内容:Java代码审计——Fastjson TemplatesImpl调用链 相关原理,可以参考:Jackson 反序列化漏洞原理 …...
【2023】DevOps、SRE、运维开发面试宝典之Kubernetes相关面试题
文章目录 1、Kubernetes集群的特点?2、Kubernetes集群各节点的组件有那些?分别有什么作用?3、简述Kubernetes集群的工作原理4、什么是Pod资源5、Label标签的作用?6、Deployment控制器与Statfulset控制器的区别?7、Pod拉取镜像的三种策略?8、简述Pod的生命周期9、Pod的生命…...
DeepSeek 赋能智慧能源:微电网优化调度的智能革新路径
目录 一、智慧能源微电网优化调度概述1.1 智慧能源微电网概念1.2 优化调度的重要性1.3 目前面临的挑战 二、DeepSeek 技术探秘2.1 DeepSeek 技术原理2.2 DeepSeek 独特优势2.3 DeepSeek 在 AI 领域地位 三、DeepSeek 在微电网优化调度中的应用剖析3.1 数据处理与分析3.2 预测与…...

相机Camera日志实例分析之二:相机Camx【专业模式开启直方图拍照】单帧流程日志详解
【关注我,后续持续新增专题博文,谢谢!!!】 上一篇我们讲了: 这一篇我们开始讲: 目录 一、场景操作步骤 二、日志基础关键字分级如下 三、场景日志如下: 一、场景操作步骤 操作步…...
【磁盘】每天掌握一个Linux命令 - iostat
目录 【磁盘】每天掌握一个Linux命令 - iostat工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景 注意事项 【磁盘】每天掌握一个Linux命令 - iostat 工具概述 iostat(I/O Statistics)是Linux系统下用于监视系统输入输出设备和CPU使…...

前端开发面试题总结-JavaScript篇(一)
文章目录 JavaScript高频问答一、作用域与闭包1.什么是闭包(Closure)?闭包有什么应用场景和潜在问题?2.解释 JavaScript 的作用域链(Scope Chain) 二、原型与继承3.原型链是什么?如何实现继承&a…...

IT供电系统绝缘监测及故障定位解决方案
随着新能源的快速发展,光伏电站、储能系统及充电设备已广泛应用于现代能源网络。在光伏领域,IT供电系统凭借其持续供电性好、安全性高等优势成为光伏首选,但在长期运行中,例如老化、潮湿、隐裂、机械损伤等问题会影响光伏板绝缘层…...
React---day11
14.4 react-redux第三方库 提供connect、thunk之类的函数 以获取一个banner数据为例子 store: 我们在使用异步的时候理应是要使用中间件的,但是configureStore 已经自动集成了 redux-thunk,注意action里面要返回函数 import { configureS…...

AirSim/Cosys-AirSim 游戏开发(四)外部固定位置监控相机
这个博客介绍了如何通过 settings.json 文件添加一个无人机外的 固定位置监控相机,因为在使用过程中发现 Airsim 对外部监控相机的描述模糊,而 Cosys-Airsim 在官方文档中没有提供外部监控相机设置,最后在源码示例中找到了,所以感…...
【Elasticsearch】Elasticsearch 在大数据生态圈的地位 实践经验
Elasticsearch 在大数据生态圈的地位 & 实践经验 1.Elasticsearch 的优势1.1 Elasticsearch 解决的核心问题1.1.1 传统方案的短板1.1.2 Elasticsearch 的解决方案 1.2 与大数据组件的对比优势1.3 关键优势技术支撑1.4 Elasticsearch 的竞品1.4.1 全文搜索领域1.4.2 日志分析…...

Linux-进程间的通信
1、IPC: Inter Process Communication(进程间通信): 由于每个进程在操作系统中有独立的地址空间,它们不能像线程那样直接访问彼此的内存,所以必须通过某种方式进行通信。 常见的 IPC 方式包括&#…...
02-性能方案设计
需求分析与测试设计 根据具体的性能测试需求,确定测试类型,以及压测的模块(web/mysql/redis/系统整体)前期要与相关人员充分沟通,初步确定压测方案及具体的性能指标QA完成性能测试设计后,需产出测试方案文档发送邮件到项目组&…...