04 Android基础--RelativeLayout

news/2024/5/19 3:41:06/文章来源:https://blog.csdn.net/sugerfle/article/details/129301667

04 Android基础--RelativeLayout

    • 什么是RelativeLayout?
    • RelativeLayout的常见用法:

什么是RelativeLayout?

相对布局(RelativeLayout)是一种根据父容器兄弟控件作为参照来确定控件位置的布局方式。

根据父容器定位
在相对布局中,可以通过以下的属性让的组合让控件处于父容器左上角、右上角、左下角、右下角、上下左右居中,正居中等九个位置。属性如下:

  1. android:layout_alignParentLeft=“true” 父容器左边
  2. android:layout_alignParentRight=“true” 父容器右边
  3. android:layout_alignParentTop=“true” 父容器顶部
  4. android:layout_alignParentBottom=“true” 父容器底部
  5. android:layout_centerHorizontal=“true” 水平方向居中
  6. android:layout_centerVertical=“true” 垂直方向居中
  7. android:layout_centerInParent=“true” 水平垂直都居中

在这里插入图片描述

根据兄弟控件定位
在相对布局中,还支持通过已确定位置的控件作为参考来确定其他控件的位置,以下的属性让的组合让控件处于另外控件左上角、右上角、左下角、右下角、正上方、正下方、正左方、正右方等位置。属性如下:

  1. android:layout_toLeftOf=“@+id/button1” 在button1控件左方
  2. android:layout_toRightOf=“@+id/button1” 在button1控件右方
  3. android:layout_above=“@+id/button1” 在button1控件上方
  4. android:layout_below=“@+id/button1” 在button1控件下方
  5. android:layout_alignLeft=“@+id/button1” 与button1控件左边平齐
  6. android:layout_alignRight=“@+id/button1” 与button1控件右边平齐
  7. android:layout_alignTop=“@+id/button1” 与button1控件上边平齐
  8. 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 标签:位于父容器左边与父容器右边,且水平竖直居中。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_76425.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

maven高级知识。

目录 一、分模块开发 1、分模块开发设计 2、依赖管理 二、继承和聚合 1、聚合 2、继承 三、属性 1、基本介绍 2、版本管理 四、多环境配置与应用 1、多环境开发 2、跳过测试 五、私服 1、私服安装 2、私服仓库分类 一、分模块开发 1、分模块开发设计 ▶ 示意图 …

南卡Neo骨传导运动耳机发布,重塑骨传导耳机舒适听感新体验!

近日&#xff0c;在骨传导耳机领域中最专业的南卡发布了今年全新系列——NEO&#xff0c;如果说南卡Runner Pro4的音质是偏向于节奏性&#xff0c;那么这款南卡NEO是更加偏向于沉稳性节奏&#xff0c;能够轻松征服轻运动场景&#xff0c;此系列在舒适度以及音质上&#xff0c;更…

【GNN笔记】GNN图论文相关笔记公开汇总清单

图神经网络相关论文笔记清单持续待更....&#x1f600; &#x1f427;&#x1f427;&#x1f427;&#x1f427;~【异构图笔记】1. 异构图笔记部分示例2. 异构图笔记清单罗列【图-注意力机制笔记】1. 图-注意力机制笔记部分示例2. 图-注意力机制笔记清单罗列这是一份有关我自己…

经典蓝牙Sniff Mode

文章目录IntroductionApplicationSniff Sub-ratingReferenceIntroduction Sniff mode为两个已连接的经典蓝牙设备提供了有效的降低功耗的方法。我们知道&#xff0c;当没有数据需要传输的时候&#xff0c;两个已连接的蓝牙设备之间也需要每两个slots完成一次POLL packet - NUL…

新版本GPU加速的tensorflow库的配置方法

本文介绍在Anaconda环境中&#xff0c;配置可以用GPU运行的Python新版tensorflow库的方法。 在上一篇文章Anaconda配置Python新版本tensorflow库&#xff08;CPU、GPU通用&#xff09;的方法&#xff08;https://blog.csdn.net/zhebushibiaoshifu/article/details/129285815&am…

Torch同时训练多个模型

20230302 引言 在进行具体的研究时&#xff0c;利用Torch进行编程&#xff0c;考虑到是不是能够同时训练两个模型呢&#xff1f;&#xff01;而且利用其中一个模型的输出来辅助另外一个模型进行学习。这一点&#xff0c;在我看来应该是很简单的&#xff0c;例如GAN网络同时训…

HOT100--(5)最长回文子串

点击查看题目详情 中心扩散法 思路&#xff1a; 遍历字符串&#xff0c;以每个字符为中心点向两边扩散&#xff0c;如果遇到不一样的就跳出循环。以此类推&#xff0c;最后截取最大回文串返回。 细节 字符个数不一定都是奇数。当个数是偶数的是时候&#xff0c;我们可以“忽…

Canal数据同步配置

文章目录Canal数据同步配置0.canal工作原理1.**检查binlog功能是否有开启**2.如果显示状态为OFF表示该功能未开启&#xff0c;开启binlog功能3.**在mysql里面添加以下的相关用户和权限**4.下载安装Canal服务5.修改配置文件6.进入bin目录下启动7.idea中配置Canal数据同步配置 c…

Java接口专题

基本介绍 接口给出一些没有实现的方法&#xff0c;封装到一起&#xff0c;到某个类使用时再根据具体情况把这些方法写出来。 注意&#xff1a;在jdk7之前&#xff0c;接口里所有的方法都是抽象方法。在jdk8之后接口中可以有静态方法&#xff0c;默认方法 interface 接口名{/…

MySQL 数据库创建不了外键约束

在数据库的表里面创建不了外键约束❓❓❓ 没错&#xff0c;以我名侦探 q 的分析&#xff08;狗屁&#xff01;&#xff01;&#xff01;&#xff09;&#xff0c;真相只有一个❗❗❗ 那就是&#xff1a;你表的存储引擎非 InnoDB&#xff0c;外键约束只有存储引擎是 InnoDB 才…

flutter window安装过程

这里写自定义目录标题#下载相关官网地址&#xff1a;https://flutter.cn/docs/get-started/install/windows 根据官网下载相关包flutter_windows_3.7.5-stable.zip 解压到c盘&#xff0c;在path配置相关解压路径(c:\flutter)。 执行 where flutter dart &#xff0c;发现没有提…

APP测试面试题汇总(基础篇、进阶篇)

一、基础篇1、请介绍一下&#xff0c;APP测试流程&#xff1f;APP测试流程与web测试流程类似&#xff0c;分为如下七个阶段&#xff1a;1.根据需求说明书编写测试计划&#xff1b;2.制定测试方案&#xff0c;主要是测试任务、测试人员和测试时间的分配&#xff1b;3.测试准备&a…

离散事件动态系统

文章目录离散事件动态系统ppt离散事件系统建模离散事件动态系统的基本组成元素离散事件动态系统仿真具体建模petri建模实例离散事件动态系统 ppt ppt 仿真建模步骤 离散事件系统建模 from&#xff1a;离散事件系统建模 离散事件动态系统的基本组成元素 &#xff08;1&am…

【备战面试】每日10道面试题打卡-Day2

本篇总结的是Java基础知识相关的面试题&#xff0c;后续也会更新其他相关内容 文章目录1、 和 equals 的区别是什么&#xff1f;2、你重写过 hashcode 和 equals 吗&#xff0c;为什么重写equals时必须重写hashCode方法&#xff1f;3、为什么Java中只有值传递&#xff1f;4、BI…

工业机器人有哪些类型?如何利用工业网关集中监测管理?

工业机器人在制造业中的应用与日俱增&#xff0c;使用工业机器人&#xff0c;不仅提高了设备和场地的利用率&#xff0c;还能保持稳定的产品水平。随着工业机器人的大规模部署&#xff0c;对于数量众多、类型各异、功能不一的机器人的监测、管理和维护&#xff0c;也成为企业面…

如何提高软件测试效率 降低开发成本?

1、单元测试以开发人员为主 测试分工需根据测试人员的特点进行&#xff0c;而单元测试应以开发人员为主&#xff0c;以保障每个单元能够完成设计的功能。集成测试也可以以开发人员为主进行。当软件体系结构完成后&#xff0c;独立测试人员应尽量选择比较熟悉相关领域的人员。​…

Webpack-好文

webpack是一个前端资源加载/打包工具&#xff0c;会根据模块的依赖关系进行静态分析&#xff0c;然后将这些模块按照指定的规则生成对应的静态资源Webpack打包js文件创建一个文件夹&#xff0c;cmd进入到终端&#xff0c;运行npm install -g webpack webpack-cli安装webpack we…

原生微信小程序引入npm和安装Vant Weapp

目录一、引入npm安装Vant Weapp1、引入npm2、安装Vant Weapp3、修改 app.json4、修改 project.config.json二、构建npm一、引入npm安装Vant Weapp 环境&#xff1a;Windows10 开发工具&#xff1a;微信开发者工具 本地环境&#xff1a;已安装过node.js 1、引入npm cmd进入到你…

动态内存基础(一)

动态内存基础 ● 栈内存 堆内存 V.S. – 栈内存的特点&#xff1a;更好的局部性&#xff0c;对象自动销毁 – 堆内存的特点&#xff1a;运行期动态扩展&#xff0c;需要显式释放 ● 在 C 中通常使用 new 与 delete 来构造、销毁对象 int* fun() {int res;return &res; //…

|干货 | 五种常用类型之String字符串详解

一. 背景说明小白&#xff1a;哥&#xff0c;java中String是最常用类型&#xff0c;Redis中也是吗?哥&#xff1a;差不多&#xff0c;我给你稍微讲一下。二. 数据类型依据Redis官网&#xff0c;目前Redis数据类型共计九种。具体整理如下&#xff1a;常用的数据类型有&#xff…