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的生命…...
ESP32音频播放终极指南:从SD卡播放MP3到网络流媒体的完整解决方案
ESP32音频播放终极指南:从SD卡播放MP3到网络流媒体的完整解决方案 【免费下载链接】ESP32-audioI2S Play mp3 files from SD via I2S 项目地址: https://gitcode.com/gh_mirrors/es/ESP32-audioI2S 想要在ESP32上构建专业的音频播放系统吗?ESP32-…...
【独家首发】Sora 2正式版未公开能力清单:原生支持3D空间锚点+时间轴语义编辑+版权水印嵌入(附OpenAI内部文档节选)
更多请点击: https://intelliparadigm.com 第一章:Sora 2正式版核心能力全景概览 多模态时序理解与生成一体化 Sora 2正式版突破性地将文本、图像、音频及物理运动参数统一编码至共享时空潜空间,支持长达120秒、1080p分辨率的连贯视频生成。…...
高海拔环境下的硬件设计挑战与GPS定位故障分析
1. 从数据记录到真实体验:高海拔环境下的技术挑战作为一名电子工程师,我习惯了在实验室里与精密的仪器和数据打交道,一切都在可控范围内。但当你带着自己设计的设备,踏上非洲之巅乞力马扎罗的征途时,现实会给你上一堂生…...
基于LLM的多智能体协作框架:从原理到实践构建自主开发团队
1. 项目概述与核心价值最近在开源社区里,一个名为zxkane/autonomous-dev-team的项目引起了我的注意。乍一看这个标题,你可能会联想到科幻电影里的全自动机器人编程,或者是一些过于理想化的“AI接管开发”的噱头。但在我花时间深入研究和实践之…...
开源自托管看板工具:基于Preact+Hono+SQLite的零云依赖方案
1. 项目概述:一个为自托管与AI协作而生的看板应用如果你正在寻找一个可以完全掌控在自己手里、没有订阅费用、又能无缝集成到你自己产品中的看板工具,那么clawnify/open-kanban这个项目值得你花时间深入研究。它不是一个玩具,而是一个生产就绪…...
Windows运行Android应用终极指南:APK Installer让你的电脑秒变安卓手机
Windows运行Android应用终极指南:APK Installer让你的电脑秒变安卓手机 【免费下载链接】APK-Installer An Android Application Installer for Windows 项目地址: https://gitcode.com/GitHub_Trending/ap/APK-Installer 在移动应用生态日益丰富的今天&…...
对lsof、tcpdump、strace命令的简单记录
1. lsof (List Open Files) —— “谁占用了资源?” 核心哲学:Linux 中一切皆文件(包括磁盘文件、网络 Socket、设备)。 常用操作:lsof -i :15000:查看指定端口的进程占用及连接状态(LISTEN/EST…...
Baetyl开源社区贡献指南:如何参与边缘计算框架的代码与文档开发
Baetyl开源社区贡献指南:如何参与边缘计算框架的代码与文档开发 【免费下载链接】baetyl Extend cloud computing, data and service seamlessly to edge devices. 项目地址: https://gitcode.com/gh_mirrors/ba/baetyl 欢迎来到Baetyl开源边缘计算框架的贡献…...
Java十道高频面试题(一)
Java基础与集合1. HashMap的底层数据结构是什么?(JDK 1.7 vs 1.8)考察点:数据结构演进、哈希冲突解决、扩容死循环问题。参考答案:HashMap在JDK 1.7和1.8中有着本质的区别,主要体现在底层结构和扩容机制上&…...
【实战篇】Nginx反向代理负载均衡:从轮询到权重的策略演进
1. 反向代理与负载均衡基础认知 第一次接触Nginx的反向代理功能时,我盯着配置文件里的proxy_pass参数看了半天。这行看似简单的配置,背后其实隐藏着现代分布式系统的核心设计思想。想象一下这样的场景:当你在电商网站点击"立即购买"…...
