使用supportFragmentManager管理多个fragment切换
android studio创建的项目就没有一个简单点的框架,生成的代码都是繁琐而复杂,并且不实用。
国内的页面一般都是TAB页面的比较多,老外更喜欢侧边菜单。
如果我们使用一个activity来创建程序,来用占位符管理多个fragment切换,这里水一篇最简单直接的做法。
源码:
https://download.csdn.net/download/robinfoxnan/89485371?spm=1001.2014.3001.5503
预览:https://img-blog.csdnimg.cn/direct/e38ca75c7a694b049366ef05da984ef6.jpeg
## **1. Java**实现
在 Android 开发中,使用 FragmentManager 来管理多个 Fragment 页面是一个常见的做法。可以通过以下步骤在主页面的占位符上替换多个 Fragment:
-
创建主 Activity 布局:在你的主 Activity 布局文件中,创建一个
FrameLayout作为占位符,用于显示Fragment。<!-- activity_main.xml --> <FrameLayoutandroid:id="@+id/fragment_container"android:layout_width="match_parent"android:layout_height="match_parent" /> -
创建 Fragments:创建多个
Fragment,每个Fragment都有自己的布局和逻辑。// ExampleFragment.java public class ExampleFragment extends Fragment {@Nullable@Overridepublic View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {return inflater.inflate(R.layout.fragment_example, container, false);} }<!-- fragment_example.xml --> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><!-- Fragment content goes here --><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Example Fragment" /> </LinearLayout> -
在主 Activity 中管理 Fragments:在你的主 Activity 中使用
FragmentManager来替换占位符中的Fragment。// MainActivity.java public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 默认加载的 Fragmentif (savedInstanceState == null) {getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExampleFragment()).commit();}}// 用于切换 Fragment 的方法public void switchFragment(Fragment fragment) {getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment).addToBackStack(null).commit();} } -
切换 Fragment:在主 Activity 中调用
switchFragment方法来切换不同的Fragment。// 切换到另一个 Fragment switchFragment(new AnotherFragment());
通过这种方式,你可以在主页面的占位符上动态替换多个 Fragment 页面。你可以根据需要在不同的事件(如按钮点击)中调用 switchFragment 方法来切换不同的 Fragment。
2.kotlin实现
2.1 添加基础切换流程
下面是用 Kotlin 实现上述功能的步骤:
-
创建主 Activity 布局:在你的主 Activity 布局文件中,创建一个
FrameLayout作为占位符,用于显示Fragment。<!-- activity_main.xml --> <FrameLayoutandroid:id="@+id/fragment_container"android:layout_width="match_parent"android:layout_height="match_parent" /> -
创建 Fragments:创建多个
Fragment,每个Fragment都有自己的布局和逻辑。// ExampleFragment.kt class ExampleFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_example, container, false)} }<!-- fragment_example.xml --> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><!-- Fragment content goes here --><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Example Fragment" /> </LinearLayout> -
在主 Activity 中管理 Fragments:在你的主 Activity 中使用
FragmentManager来替换占位符中的Fragment。// MainActivity.kt class MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)// 默认加载的 Fragmentif (savedInstanceState == null) {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, ExampleFragment()).commit()}}// 用于切换 Fragment 的方法fun switchFragment(fragment: Fragment) {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, fragment).addToBackStack(null).commit()} } -
切换 Fragment:在主 Activity 中调用
switchFragment方法来切换不同的Fragment。// 切换到另一个 Fragment switchFragment(AnotherFragment())
通过这种方式,可以在主页面的占位符上动态替换多个 Fragment 页面。你可以根据需要在不同的事件(如按钮点击)中调用 switchFragment 方法来切换不同的 Fragment。
2.2 页面中获取主界面
在 AnotherFragment 中获取 MainActivity 的实例并调用 switchFragment 方法,你可以使用 Kotlin 的 activity 属性,它返回当前 Fragment 所附着的 Activity 实例。你需要确保类型转换安全,避免强制转换引起的异常。
下面是一个示例:
-
创建
AnotherFragment:在AnotherFragment中编写逻辑来获取MainActivity实例并调用switchFragment方法。// AnotherFragment.kt class AnotherFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_another, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)// 假设你有一个按钮来触发 Fragment 切换val button: Button = view.findViewById(R.id.switch_fragment_button)button.setOnClickListener {(activity as? MainActivity)?.switchFragment(ExampleFragment())}} }<!-- fragment_another.xml --> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><!-- Fragment content goes here --><Buttonandroid:id="@+id/switch_fragment_button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Switch to Example Fragment" /> </LinearLayout> -
更新
MainActivity:确保MainActivity里有一个方法switchFragment可以被调用。// MainActivity.kt class MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)// 默认加载的 Fragmentif (savedInstanceState == null) {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, ExampleFragment()).commit()}}// 用于切换 Fragment 的方法fun switchFragment(fragment: Fragment) {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, fragment).addToBackStack(null).commit()} }
通过这种方式,你可以在 AnotherFragment 中获取 MainActivity 的实例并调用 switchFragment 方法来切换 Fragment。这利用了 Kotlin 的安全类型转换 (as?) 来确保在类型转换失败时返回 null,而不是引发异常。
2.3 复用fragment
每次调用 switchFragment 方法时,都会创建一个新的 Fragment 实例并替换当前的 Fragment。如果你希望在切换 Fragment 时复用已有的 Fragment 实例,而不是每次都创建一个新的,可以在 MainActivity 中维护这些 Fragment 的实例。
下面是一个示例,展示如何在 MainActivity 中维护 Fragment 实例,并在切换时复用这些实例:
-
在
MainActivity中维护Fragment实例:// MainActivity.kt class MainActivity : AppCompatActivity() {private lateinit var exampleFragment: ExampleFragmentprivate lateinit var anotherFragment: AnotherFragmentoverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)if (savedInstanceState == null) {// 初始化 Fragment 实例exampleFragment = ExampleFragment()anotherFragment = AnotherFragment()// 默认加载的 FragmentsupportFragmentManager.beginTransaction().replace(R.id.fragment_container, exampleFragment).commit()} else {// 恢复已存在的 Fragment 实例exampleFragment = supportFragmentManager.findFragmentByTag("ExampleFragment") as ExampleFragmentanotherFragment = supportFragmentManager.findFragmentByTag("AnotherFragment") as AnotherFragment}}// 用于切换 Fragment 的方法fun switchFragment(fragment: Fragment, tag: String) {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, fragment, tag).addToBackStack(null).commit()} } -
在
AnotherFragment中调用switchFragment方法:// AnotherFragment.kt class AnotherFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_another, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)// 假设你有一个按钮来触发 Fragment 切换val button: Button = view.findViewById(R.id.switch_fragment_button)button.setOnClickListener {(activity as? MainActivity)?.switchFragment((activity as MainActivity).exampleFragment, "ExampleFragment")}} }
通过这种方式,你可以在 MainActivity 中维护 Fragment 的实例,并在切换时复用这些实例,而不是每次都创建一个新的 Fragment。在调用 switchFragment 方法时,通过传递 Fragment 实例和对应的标签(tag)来替换当前的 Fragment。
2.4 map来管理多个fragment
可以使用一个 Map 来管理多个 Fragment 实例。这可以使得管理 Fragment 的实例更加灵活和高效。你可以在 MainActivity 中使用 Map 来存储 Fragment 实例,并在需要切换 Fragment 时从 Map 中获取相应的实例。
以下是一个示例,展示如何使用 Map 来管理多个 Fragment 实例:
-
在
MainActivity中定义一个Map来存储Fragment实例:// MainActivity.kt class MainActivity : AppCompatActivity() {private val fragmentMap = mutableMapOf<String, Fragment>()override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)if (savedInstanceState == null) {// 初始化 Fragment 实例并存储到 Map 中fragmentMap["ExampleFragment"] = ExampleFragment()fragmentMap["AnotherFragment"] = AnotherFragment()// 默认加载的 FragmentswitchFragment("ExampleFragment")}}// 用于切换 Fragment 的方法fun switchFragment(tag: String) {val fragment = fragmentMap[tag]fragment?.let {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, it, tag).addToBackStack(null).commit()}} } -
在
AnotherFragment中调用switchFragment方法:// AnotherFragment.kt class AnotherFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_another, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)// 假设你有一个按钮来触发 Fragment 切换val button: Button = view.findViewById(R.id.switch_fragment_button)button.setOnClickListener {(activity as? MainActivity)?.switchFragment("ExampleFragment")}} } -
在
ExampleFragment中调用switchFragment方法(类似AnotherFragment):// ExampleFragment.kt class ExampleFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_example, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)// 假设你有一个按钮来触发 Fragment 切换val button: Button = view.findViewById(R.id.switch_fragment_button)button.setOnClickListener {(activity as? MainActivity)?.switchFragment("AnotherFragment")}} }
通过这种方式,你可以使用一个 Map 来管理多个 Fragment 实例,并在需要时通过标签(tag)来切换 Fragment。这使得 Fragment 的管理更加灵活和高效。
2.5 使用库模块中的界面
当然可以!在 Android 项目中,你可以导入其他模块或库,并在你的应用中使用它们定义的 Fragment。以下是一个示例,展示如何导入一个模块并使用该模块中定义的 Fragment。
假设你有一个名为 mylibrary 的模块,其中定义了一个 CustomFragment。
-
在你的项目中导入模块:
首先,确保你的项目的
settings.gradle文件中包含了该模块:include ':app', ':mylibrary' -
添加模块依赖:
在你的应用模块的
build.gradle文件中添加对mylibrary模块的依赖:dependencies {implementation project(':mylibrary')// 其他依赖项 } -
在你的模块中定义
Fragment:在
mylibrary模块中定义一个CustomFragment:// mylibrary/src/main/java/com/example/mylibrary/CustomFragment.kt package com.example.mylibraryimport android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragmentclass CustomFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_custom, container, false)} }<!-- mylibrary/src/main/res/layout/fragment_custom.xml --> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><!-- Fragment content goes here --><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Custom Fragment" /> </LinearLayout> -
在主应用中使用
CustomFragment:现在你可以在你的主应用中使用
mylibrary模块中定义的CustomFragment。// MainActivity.kt import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import com.example.mylibrary.CustomFragmentclass MainActivity : AppCompatActivity() {private val fragmentMap = mutableMapOf<String, Fragment>()override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)if (savedInstanceState == null) {// 初始化 Fragment 实例并存储到 Map 中fragmentMap["ExampleFragment"] = ExampleFragment()fragmentMap["AnotherFragment"] = AnotherFragment()fragmentMap["CustomFragment"] = CustomFragment()// 默认加载的 FragmentswitchFragment("ExampleFragment")}}// 用于切换 Fragment 的方法fun switchFragment(tag: String) {val fragment = fragmentMap[tag]fragment?.let {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, it, tag).addToBackStack(null).commit()}} } -
在
AnotherFragment中调用switchFragment方法:// AnotherFragment.kt class AnotherFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_another, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)// 假设你有一个按钮来触发 Fragment 切换val button: Button = view.findViewById(R.id.switch_fragment_button)button.setOnClickListener {(activity as? MainActivity)?.switchFragment("CustomFragment")}} }
通过这种方式,你可以导入一个模块,并在主应用中使用该模块中定义的 Fragment。这使得代码更加模块化和可复用。
相关文章:
使用supportFragmentManager管理多个fragment切换
android studio创建的项目就没有一个简单点的框架,生成的代码都是繁琐而复杂,并且不实用。 国内的页面一般都是TAB页面的比较多,老外更喜欢侧边菜单。 如果我们使用一个activity来创建程序,来用占位符管理多个fragment切换&…...
开源模型应用落地-FastAPI-助力模型交互-WebSocket篇(六)
一、前言 使用 FastAPI 可以帮助我们更简单高效地部署 AI 交互业务。FastAPI 提供了快速构建 API 的能力,开发者可以轻松地定义模型需要的输入和输出格式,并编写好相应的业务逻辑。 FastAPI 的异步高性能架构,可以有效支持大量并发的预测请求,为用户提供流畅的交互体验。此外,F…...
独立开发者系列(17)——MYSQL的常见异常整理
虽然安装MYSQL到本地很简单,但是数据库报错还是经常出现,这个时候,需要我们进行逐步检查与修复。作为我们最常用的开发软件,无论切换php/go/python/node/java,数据库的身影都少不了,对于我们储存数据而言&a…...
【ajax实战02】数据管理网站—验证码登录
一:数据提交(提交手机验证码) 核心思路整理 利用form-serialize插件,收集对象形式的表单数据后,一并提交给服务器。后得到返回值,进一步操作 基地址: axios.defaults.baseURL http://geek.…...
人工智能在反无人机中的应用介绍
人工智能技术在无人机的发展中扮演着至关重要的角色,这一作用在反无人机技术领域同样显著。随着无人机技术的发展,飞行器具备了微小尺寸、高速机动性,以及可能采用的隐蔽或低空飞行轨迹等特性。这些特性使得传统的人工监视和控制手段面临着重…...
【力扣 - 每日一题】3115. 质数的最大距离(一次遍历、头尾遍历、空间换时间、埃式筛、欧拉筛、打表)Golang实现
原题链接 题目描述 给你一个整数数组 nums。 返回两个(不一定不同的)质数在 nums 中 下标 的 最大距离。 示例 1: 输入: nums [4,2,9,5,3] 输出: 3 解释: nums[1]、nums[3] 和 nums[4] 是质数。因此答…...
【Gin】项目搭建 一
环境准备 首先确保自己电脑安装了Golang 开始项目 1、初始化项目 mkdir gin-hello; # 创建文件夹 cd gin-hello; # 需要到刚创建的文件夹里操作 go mod init goserver; # 初始化项目,项目名称:goserver go get -u github.com/gin-gonic/gin; # 下载…...
C++ 和C#的差别
首先把眼睛瞪大,然后憋住一口气,读下去: 1、CPP 就是C plus plus的缩写,中国大陆的程序员圈子中通常被读做"C加加",而西方的程序员通常读做"C plus plus",它是一种使用非常广泛的计算…...
Vue2组件传值(通信)的方式
目录 1.父传后代 ( 后代拿到了父的数据 )1. 父组件引入子组件,绑定数据2. 子组件直接使用父组件的数据3. 依赖注入(使用 provide/inject API)1.在祖先组件中使用 provide2.在后代组件中使用 inject 2.后代传父 (父拿到了后代的数据)1. 子组件…...
【数据结构 - 时间复杂度和空间复杂度】
文章目录 <center>时间复杂度和空间复杂度算法的复杂度时间复杂度大O的渐进表示法常见时间复杂度计算举例 空间复杂度实例 时间复杂度和空间复杂度 算法的复杂度 算法在编写成可执行程序后,运行时需要耗费时间资源和空间(内存)资源 。因此衡量一个算法的好坏&…...
telegram支付
今天开始接入telegram支付,参考教程这个是telegram的官方说明,详细介绍了机器人支付API。 文章公开地址 新建机器人 因为支付是一个单独的系统,所以在做支付的时候单独创建了一个bot,没有用之前的bot了,特意这样将其分开。创建bot的方法和之前不变,这里不过多介绍。 获…...
elasticsearch-6.8.23的集群搭建过程
三个节点的 ElasticSearch 集群搭建步骤 准备三台机器:28.104.87.98、28.104.87.100、28.104.87.101 和 ElasticSearch 的安装包 elasticsearch-6.8.23.tar.gz ----------------------------- 28.104.87.98,使用 root 用户操作 ----------------------…...
javascript输出语法
javascript输出有三种方式 一种是弹窗输出,就是网页弹出一个对话框,弹出输出内容 语法是aler(内容) 示例代码如下 <body> <script> alert(你好); </script> </body> 这段代码运行后网页会出现一个对话框,弹出你…...
仓库管理系统26--权限设置
原创不易,打字不易,截图不易,多多点赞,送人玫瑰,留有余香,财务自由明日实现 1、权限概述 在应用软件中,通常将软件的功能分为若干个子程序,通过主程序调用。那么,通过…...
d3dx9_43.dll丢失怎么解决?d3dx9_43.dll怎么安装详细教程
在使用计算机中,如果遇到d3dx9_43.dll丢失或许找不到d3dx9_43.dll无法运行打开软件怎么办?这个是非常常见问题,下面我详细介绍一下d3dx9_43.dll是什么文件与d3dx9_43.dll的各种问题以及d3dx9_43.dll丢失的多个解决方法! 一、d3dx9…...
[C++] 退出清理函数解读(exit、_exit、abort、atexit)
说明:在C中,exit、_exit(或_Exit)、abort和atexit是用于控制程序退出和清理的标准库函数。下面是对这些函数的详细解读: exit 函数原型:void exit(int status);作用:exit函数用于正常退出程序…...
代码随想录(回溯)
组合(Leetcode77) 思路 用递归每次遍历从1-n得数,然后list来记录是不是组合到k个了,然后这个每次for循环的开始不能和上一个值的开始重复,所以设置个遍历开始索引startindex class Solution {static List<List<…...
编译原理1
NFA&DFA 在正规式的等价证明可以借助正规集,也可以通过有限自动机DFA来证明等价,以下例题是针对DFA证明正规式的等价,主要步骤是①NFA;②状态转换表; ③状态转换矩阵; ④化简DFA; 文法和语…...
【信息系统项目管理师知识点速记】组织通用管理:流程管理
23.2 流程管理 通过流程视角能够真正看清楚组织系统的本质与内在联系,理顺流程能够理顺整个组织系统。流程是组织运行体系的框架基础,流程框架的质量影响和决定了整个组织运行体系的质量。把流程作为组织运行体系的主线,配备满足流程运作需要的资源,并构建与流程框架相匹配…...
前端 JS 经典:箭头函数的意义
箭头函数是为了消除函数的二义性。 1. 二义性 函数的二义性指函数有不同的两种用法,就造成了二义性,函数的两种用法:1. 指令序列。2. 构造器 1.1 指令序列 就是调用函数,相当于将函数内部的代码再从头执行一次。 1.2 构造器 …...
Z-Image-Turbo-rinaiqiao-huiyewunv参数详解:Turbo模型推荐步数/CFG/精度配置原理剖析
Z-Image-Turbo-rinaiqiao-huiyewunv参数详解:Turbo模型推荐步数/CFG/精度配置原理剖析 1. 引言:为什么你的AI绘图效果总是不理想? 如果你用过一些AI绘图工具,可能会遇到这样的问题:生成的图片要么模糊不清࿰…...
比迪丽模型在数据库课程设计中的应用:ER图可视化增强
比迪丽模型在数据库课程设计中的应用:ER图可视化增强 1. 引言 数据库课程设计是计算机专业学生的必修实践环节,其中ER图(实体-关系图)的设计与呈现是核心难点。传统工具绘制的ER图往往显得枯燥抽象,学生难以直观理解…...
Qwen3-TTS-12Hz-1.7B-CustomVoice惊艳效果:葡萄牙语足球解说+俄语天气预报语音集
Qwen3-TTS-12Hz-1.7B-CustomVoice惊艳效果:葡萄牙语足球解说俄语天气预报语音集 1. 多语言语音合成的突破性进展 语音合成技术正在经历一场革命性的变革,而Qwen3-TTS-12Hz-1.7B-CustomVoice无疑是这场变革中的佼佼者。这个模型不仅在技术架构上实现了重…...
国产AI 调用量反超美国,22个免费大模型API集结,DMXAPI 成开发者首选
据 OpenRouter 最新数据,2026 年 3 月中国 AI 大模型周调用量达 4.69 万亿 Token,连续两周超越美国,全球调用量前三席位被小米 MiMo-V2-Pro、阶跃星辰 Step 3.5 Flash、MiniMax M2.5 包揽,国产模型凭性能与性价比获全球开发者认可…...
OpenClaw+GLM-4.7-Flash:科研数据收集与处理自动化方案
OpenClawGLM-4.7-Flash:科研数据收集与处理自动化方案 1. 为什么科研需要自动化助手 去年冬天,我在整理一篇跨学科综述论文时,经历了连续三周每天14小时的手动文献筛选和数据提取。当我在凌晨三点对着第237篇PDF文件发呆时,突然…...
数据清洗提速37倍的秘密:Polars 2.0中arrow2内核的零拷贝cast、predicate pushdown与pl.scan_parquet深度调优
第一章:Polars 2.0 大规模数据清洗技巧 面试题汇总Polars 2.0 引入了更严格的惰性执行模型、增强的字符串处理 API 以及对空值语义的统一规范,使其在面试中成为高频考察对象。高频考点聚焦于内存效率、链式操作健壮性及跨类型转换的边界处理。高效处理缺…...
AT32F403A开发板8个串口全开实战:用V2库实现多路数据同时收发(附完整代码)
AT32F403A开发板8串口全开实战:工业级多通道通信架构设计 在工业自动化、智能仓储和物联网网关等场景中,经常需要同时对接多个传感器、执行器或通信模块。传统方案往往采用多个MCU协同工作或外加串口扩展芯片,而AT32F403AVGT7凭借其原生8个串…...
基于SSM + Vue的二手物品交易网站系统(角色:用户、管理员)
文章目录前言一、详细操作演示视频二、具体实现截图三、技术栈1.前端-Vue.js2.后端-SpringBoot3.数据库-MySQL4.系统架构-B/S四、系统测试1.系统测试概述2.系统功能测试3.系统测试结论五、项目代码参考六、数据库代码参考七、项目论文示例结语前言 💛博主介绍&#…...
大模型核心技术概述:Token、Prompt、Tool与Agent的关系详解
你是不是经常听人聊AI时蹦出这些词:LLM、Token、Context、Prompt、Tool、MCP、Agent?听着好像都认识,但真要问“这到底是啥”,又有点懵。今天把这些词一个个拆开揉碎,讲清楚它们到底是啥、有啥用、又是怎么串起来的。 …...
LSM303DLHC六轴IMU硬件设计与磁场校准实战指南
1. LSM303DLHC 器件概述与工程定位LSM303DLHC 是意法半导体(STMicroelectronics)推出的一款高集成度、低功耗的六轴惯性测量单元(6-DoF IMU),由独立封装的三轴加速度计(LIS3DH 兼容架构)和三轴磁…...
