(七)Android布局类型(网格布局GridLayout)

2024-03-18 00:04

本文主要是介绍(七)Android布局类型(网格布局GridLayout),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

从表格布局中可以了解到,无法实现跨行。网格布局不仅能实现跨行、还能实现跨列,并且,该种布局能自动进行子元素的定位,在使用上,更加灵活。

知识点1:设置最大行数和最大列数

最大行数设置(假设为2):android:rowCount="2"
最大列数设置(假设为4):android:columnCount="4"

案例1:设置最大行数和最大列数(但是无法限制组件个数)

<?xml version="1.0" encoding="utf-8"?>
<GridLayout 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:rowCount="2"android:columnCount="4"tools:context=".MainActivity"><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮1"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮2"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮3"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮4"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮5"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮6"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮7"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮8"/>
</GridLayout>

从结果中可以看出,右方的布局中,看起来好像是有3行似的,前两行的右侧也没有填满

注意:设置最大行数为2,最大列数为4,并不表示只能放置8个组件,还是可以多增加组件的

刚刚说到,“该种布局能自动进行子元素的定位”,也就是说,刚刚的行数为2,列数为4,如果只放8个组件,那么就是2行4列。如果想要把组件排列为4行2列,则只需要修改代码为:

android:rowCount="4"
android:columnCount="2"

知识点2:实现跨列

核心代码:

设置跨列(假设跨2列):android:layout_columnSpan="2"

此时发现,按钮1并没有横跨按钮2的位置;按钮2空出来了,把按钮8挤到了下一行。

此时需要做两件事:1)实现跨列;2)按钮8的位置不能动

设置横向填充(具体设置代码如下),按钮1占了按钮2的位置,他们两个组件是水平方向上相邻组件,所以设置横向填充,使得按钮1不仅占据自己的位置,还要占据被跨列的位置。

android:layout_gravity="fill_horizontal"

由于按钮1占据了按钮2的位置,所有的组件都往后移了一位,导致按钮8也出现了移位。既然按钮2被按钮1占了,那么,按钮2就不应该再存在。所以,解决方法有两个,要么删除按钮2,要么注释掉按钮2。下图展示的是注释掉按钮2。

完整代码:

<?xml version="1.0" encoding="utf-8"?>
<GridLayout 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:rowCount="2"android:columnCount="4"tools:context=".MainActivity"><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnSpan="2"android:layout_gravity="fill_horizontal"android:text="按钮1"/>
<!--    <Button android:layout_width="wrap_content"-->
<!--        android:layout_height="wrap_content"-->
<!--        android:text="按钮2"/>--><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮3"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮4"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮5"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮6"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮7"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮8"/>
</GridLayout>

知识点3:实现跨行

按照跨列的思路,跨行的实现基本思路是:1)设置跨行;2)设置占满;3)将被占的组件注释掉。

1)设置跨行

android:layout_rowSpan="2"

2)设置占满

注意,由于按钮3占用的是按钮7的位置,它们两个组件是垂直关系,所以设置占满方式,要选用垂直占满。

核心代码:

android:layout_gravity="fill_vertical"

 3)3)将被占的组件注释掉,由于占用的是按钮7,所以应该注释掉按钮7对应的代码

此时发现,按钮3确实占了按钮7的位置,目的是达到了,但是高度超出了两个按钮,这是因为网格布局的高度设置为填满父容器(android:layout_height="match_parent") 

所以,将父容器的高度填满方式改为根据内容进行填充(wrap_content),那么两个按钮的高度就是网格布局的高度。

整体代码:

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="wrap_content"android:rowCount="2"android:columnCount="4"tools:context=".MainActivity"><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnSpan="2"android:layout_gravity="fill_horizontal"android:text="按钮1"/>
<!--    <Button android:layout_width="wrap_content"-->
<!--        android:layout_height="wrap_content"-->
<!--        android:text="按钮2"/>--><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_rowSpan="2"android:layout_gravity="fill_vertical"android:text="按钮3"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮4"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮5"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮6"/>
<!--    <Button android:layout_width="wrap_content"-->
<!--        android:layout_height="wrap_content"-->
<!--        android:text="按钮7"/>--><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮8"/>
</GridLayout>

进阶 

首先设置2行4列的排版

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="wrap_content"android:rowCount="2"android:columnCount="4"tools:context=".MainActivity"><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮1"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮2"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮3"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮4"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮5"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮6"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮7"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="按钮8"/>
</GridLayout>

 

实现水平均分铺满排版

原谅:手动绘制四个水平均分的按钮,很难绘制准确。大家看上图的时候,务必把四个蓝色组件框看成是一样大小的,每个宽度占红色宽度的1/4

思路:1)水平铺满,则网格布局的宽度要设置为占满父容器;2)其次,每个按钮要均分宽度,那么宽度就是不知道的,所以设置为0dp,并且还要告诉每个组件所占相等。

第一步:设置网格布局的宽度要设置为占满父容器

第二步:设置组件宽度为0dp,占比相等

核心代码:

android:layout_width="0dp"
android:layout_columnWeight="1"

注意:设置的是列占比权重相等,水平方向上均分列,看起来水平方向上每个组件宽度相等。

完整代码:

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="wrap_content"android:rowCount="2"android:columnCount="4"tools:context=".MainActivity"><Button android:layout_width="0dp"android:layout_columnWeight="1"android:layout_height="wrap_content"android:text="按钮1"/><Button android:layout_width="0dp"android:layout_columnWeight="1"android:layout_height="wrap_content"android:text="按钮2"/><Button android:layout_width="0dp"android:layout_columnWeight="1"android:layout_height="wrap_content"android:text="按钮3"/><Button android:layout_width="0dp"android:layout_columnWeight="1"android:layout_height="wrap_content"android:text="按钮4"/><Button android:layout_width="0dp"android:layout_columnWeight="1"android:layout_height="wrap_content"android:text="按钮5"/><Button android:layout_width="0dp"android:layout_columnWeight="1"android:layout_height="wrap_content"android:text="按钮6"/><Button android:layout_width="0dp"android:layout_columnWeight="1"android:layout_height="wrap_content"android:text="按钮7"/><Button android:layout_width="0dp"android:layout_columnWeight="1"android:layout_height="wrap_content"android:text="按钮8"/>
</GridLayout>

实现垂直均分铺满排版

希望的结果是:

当然,如果每列都设置为垂直均分,那么,每列效果都应该和第一列效果一致。

思路:1)垂直铺满,则网格布局的高度要设置为占满父容器;2)其次,每个按钮要均分宽度,那么高度就是不知道的,所以设置为0dp,并且还要告诉每个组件所占相等。

核心代码:

 android:layout_height="0dp"android:layout_rowWeight="1"

1)垂直铺满,则网格布局的高度要设置为占满父容器

第二步:设置组件高度为0dp,占比相等

android:layout_height="0dp"
android:layout_rowWeight="1"

完整代码:

 

<?xml version="1.0" encoding="utf-8"?>
<GridLayout 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:rowCount="2"android:columnCount="4"tools:context=".MainActivity"><Button android:layout_width="wrap_content"android:layout_height="0dp"android:layout_rowWeight="1"android:text="按钮1"/><Button android:layout_width="wrap_content"android:layout_height="0dp"android:layout_rowWeight="1"android:text="按钮2"/><Button android:layout_width="wrap_content"android:layout_height="0dp"android:layout_rowWeight="1"android:text="按钮3"/><Button android:layout_width="wrap_content"android:layout_height="0dp"android:layout_rowWeight="1"android:text="按钮4"/><Button android:layout_width="wrap_content"android:layout_height="0dp"android:layout_rowWeight="1"android:text="按钮5"/><Button android:layout_width="wrap_content"android:layout_height="0dp"android:layout_rowWeight="1"android:text="按钮6"/><Button android:layout_width="wrap_content"android:layout_height="0dp"android:layout_rowWeight="1"android:text="按钮7"/><Button android:layout_width="wrap_content"android:layout_height="0dp"android:layout_rowWeight="1"android:text="按钮8"/>
</GridLayout>

实现全屏均分铺满排版

 根据上述两个案例的学习,可以发现,水平均分则垂直方向出现空白,垂直均分,则右侧出现空白

要实现垂直和水平方向都实现均分,则将两则融合起来即可。

思路:1)网格布局的宽高均要填充满父容器;2)设置宽高均为0dp,列和行上的占比均相等

核心代码:

android:layout_width="0dp"
android:height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"

完整代码和效果

<?xml version="1.0" encoding="utf-8"?>
<GridLayout 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:rowCount="2"android:columnCount="4"tools:context=".MainActivity"><Button android:layout_width="0dp"android:height="0dp"android:layout_rowWeight="1"android:layout_columnWeight="1"android:text="按钮1"/><Button android:layout_width="0dp"android:height="0dp"android:layout_rowWeight="1"android:layout_columnWeight="1"android:text="按钮2"/><Button android:layout_width="0dp"android:height="0dp"android:layout_rowWeight="1"android:layout_columnWeight="1"android:text="按钮3"/><Button android:layout_width="0dp"android:height="0dp"android:layout_rowWeight="1"android:layout_columnWeight="1"android:text="按钮4"/><Button android:layout_width="0dp"android:height="0dp"android:layout_rowWeight="1"android:layout_columnWeight="1"android:text="按钮5"/><Button android:layout_width="0dp"android:height="0dp"android:layout_rowWeight="1"android:layout_columnWeight="1"android:text="按钮6"/><Button android:layout_width="0dp"android:height="0dp"android:layout_rowWeight="1"android:layout_columnWeight="1"android:text="按钮7"/><Button android:layout_width="0dp"android:height="0dp"android:layout_rowWeight="1"android:layout_columnWeight="1"android:text="按钮8"/>
</GridLayout>

测试1:你真的学会了吗?试试吧 

目标:设计如下界面

参考代码:

<?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="wrap_content"android:rowCount="6"android:columnCount="4"android:useDefaultMargins="true"><EditText android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="3"android:layout_columnSpan="3"android:hint="0"android:gravity="right"android:background="@null"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:gravity="center"android:text="/"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:text="1"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:text="2"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:text="3"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:text="*"/><!--第3行--><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:text="4"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:text="5"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:text="6"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:text="-"/><!--第4行--><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:text="7"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:text="8"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:text="9"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:layout_rowSpan="3"android:layout_gravity="fill"android:gravity="center"android:text="+"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:text="0"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:layout_columnSpan="2"android:text="00"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:layout_columnSpan="3"android:text="="/>
</GridLayout>

相信排版是没有问题的,但是和效果图一模一样,还是需要进行精细化处理

1)由于底部有空白,所以高度不可能是占满,可以选择根据内容自动设置高度

2)其次,组件之间有间隔,可以使用默认的外边距

综合核心代码是:

android:layout_height="wrap_content"
android:useDefaultMargins="true"

3)然后是第一个组件,特点是占据了3列,所以不仅要设置跨列,还要设置占比为其他组件的3倍;文字右对齐;如果使用的是编辑框,则会出现下划线,这个下划线需要去掉

综合核心代码是:

android:layout_columnWeight="3"
android:layout_columnSpan="3"
android:gravity="right"
android:background="@null"

4) 其他组件依次排列,实现跨行和跨列即可

测试2:你真的学会了吗?把界面放大试试

参考代码:

<?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:rowCount="6"android:columnCount="4"android:useDefaultMargins="true"><EditTextandroid:layout_width="0dp"android:layout_height="wrap_content"android:layout_columnSpan="3"android:layout_columnWeight="3"android:layout_rowWeight="1"android:layout_gravity="fill"android:background="@null"android:gravity="right|center_vertical"android:hint="0" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:layout_rowWeight="1"android:gravity="center"android:background="#eeeeee"android:text="/" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:layout_rowWeight="1"android:gravity="center"android:text="1" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:layout_rowWeight="1"android:gravity="center"android:text="2" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:layout_rowWeight="1"android:text="3" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:layout_rowWeight="1"android:gravity="center"android:text="*" /><!--第3行--><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:layout_rowWeight="1"android:gravity="center"android:text="4" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:layout_rowWeight="1"android:background="#eeeeee"android:gravity="center"android:text="5" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:layout_rowWeight="1"android:background="#eeeeee"android:gravity="center"android:text="6" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:layout_rowWeight="1"android:gravity="center"android:text="-" /><!--第4行--><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:layout_rowWeight="1"android:gravity="center"android:text="7" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:layout_rowWeight="1"android:gravity="center"android:text="8" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:layout_rowWeight="1"android:gravity="center"android:text="9" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_rowSpan="3"android:layout_columnWeight="1"android:layout_gravity="fill"android:background="#eeeeee"android:gravity="center"android:layout_rowWeight="1"android:text="+" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:layout_rowWeight="1"android:text="0" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnSpan="2"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:layout_rowWeight="1"android:text="00" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_columnSpan="3"android:layout_columnWeight="1"android:background="#eeeeee"android:gravity="center"android:layout_rowWeight="1"android:text="=" />
</GridLayout>

核心思想:1)要铺满,所以宽高都要占满父容器

android:layout_width="match_parent"
android:layout_height="match_parent"

2) 其次,第一个编辑框,要设置右对齐,且要文字垂直居中对齐

核心代码:

android:gravity="right|center_vertical"

PS:

android:gravity="center"

这个属性的设置,目的是让TextView中的文字在TextView内部垂直水平居中显示。 

这篇关于(七)Android布局类型(网格布局GridLayout)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/820613

相关文章

Python中Json和其他类型相互转换的实现示例

《Python中Json和其他类型相互转换的实现示例》本文介绍了在Python中使用json模块实现json数据与dict、object之间的高效转换,包括loads(),load(),dumps()... 项目中经常会用到json格式转为object对象、dict字典格式等。在此做个记录,方便后续用到该方

Android协程高级用法大全

《Android协程高级用法大全》这篇文章给大家介绍Android协程高级用法大全,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友跟随小编一起学习吧... 目录1️⃣ 协程作用域(CoroutineScope)与生命周期绑定Activity/Fragment 中手

python中的显式声明类型参数使用方式

《python中的显式声明类型参数使用方式》文章探讨了Python3.10+版本中类型注解的使用,指出FastAPI官方示例强调显式声明参数类型,通过|操作符替代Union/Optional,可提升代... 目录背景python函数显式声明的类型汇总基本类型集合类型Optional and Union(py

MySQL中查询和展示LONGBLOB类型数据的技巧总结

《MySQL中查询和展示LONGBLOB类型数据的技巧总结》在MySQL中LONGBLOB是一种二进制大对象(BLOB)数据类型,用于存储大量的二进制数据,:本文主要介绍MySQL中查询和展示LO... 目录前言1. 查询 LONGBLOB 数据的大小2. 查询并展示 LONGBLOB 数据2.1 转换为十

MyBatis的xml中字符串类型判空与非字符串类型判空处理方式(最新整理)

《MyBatis的xml中字符串类型判空与非字符串类型判空处理方式(最新整理)》本文给大家介绍MyBatis的xml中字符串类型判空与非字符串类型判空处理方式,本文给大家介绍的非常详细,对大家的学习或... 目录完整 Hutool 写法版本对比优化为什么status变成Long?为什么 price 没事?怎

Android 缓存日志Logcat导出与分析最佳实践

《Android缓存日志Logcat导出与分析最佳实践》本文全面介绍AndroidLogcat缓存日志的导出与分析方法,涵盖按进程、缓冲区类型及日志级别过滤,自动化工具使用,常见问题解决方案和最佳实... 目录android 缓存日志(Logcat)导出与分析全攻略为什么要导出缓存日志?按需过滤导出1. 按

C#之枚举类型与随机数详解

《C#之枚举类型与随机数详解》文章讲解了枚举类型的定义与使用方法,包括在main外部声明枚举,用于表示游戏状态和周几状态,枚举值默认从0开始递增,也可手动设置初始值以生成随机数... 目录枚举类型1.定义枚举类型(main外)2.使用生成随机数总结枚举类型1.定义枚举类型(main外)enum 类型名字

Python lambda函数(匿名函数)、参数类型与递归全解析

《Pythonlambda函数(匿名函数)、参数类型与递归全解析》本文详解Python中lambda匿名函数、灵活参数类型和递归函数三大进阶特性,分别介绍其定义、应用场景及注意事项,助力编写简洁高效... 目录一、lambda 匿名函数:简洁的单行函数1. lambda 的定义与基本用法2. lambda

C语言自定义类型之联合和枚举解读

《C语言自定义类型之联合和枚举解读》联合体共享内存,大小由最大成员决定,遵循对齐规则;枚举类型列举可能值,提升可读性和类型安全性,两者在C语言中用于优化内存和程序效率... 目录一、联合体1.1 联合体类型的声明1.2 联合体的特点1.2.1 特点11.2.2 特点21.2.3 特点31.3 联合体的大小1

MySQL 索引简介及常见的索引类型有哪些

《MySQL索引简介及常见的索引类型有哪些》MySQL索引是加速数据检索的特殊结构,用于存储列值与位置信息,常见的索引类型包括:主键索引、唯一索引、普通索引、复合索引、全文索引和空间索引等,本文介绍... 目录什么是 mysql 的索引?常见的索引类型有哪些?总结性回答详细解释1. MySQL 索引的概念2