Kennem's Blog
  • 🏠主页
  • 🔍搜索
  • 📚文章
  • ⏱时间轴
  • 🔖标签
  • 🗂️分类
  • 🙋🏻‍♂️关于
主页 📚文章

💻技术

Kotlin协程(5)

Kotlin协程(5) Binding 视图绑定 View Binding: 通过View Binding, Android 会为每个XML布局文件自动生成一个绑定类。在这个类中,每个View都有一个直接对应的属性,可以避免findViewById的使用,从而减少了手动查找视图和类型转换的工作。提高代码的安全性和可读性。 val binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) binding.textView.text = "Hello World" Data Binding: 功能比View Binding 更为强大,允许在布局文件中直接绑定UI组件到数据源(如ViewModel),这样,数据的变化会自动更新UI <data> <variable name="user" type="com.example.User"/> </data> <TextView android:text="@{user.name}"/> Activity 中: ...

2024-08-06 · 5 分钟 · 2116 字 · updated: 2024-08-13 · ShowGuan

Hugo配置与使用

Hugo配置与使用 下载PaperMod主题: git clone https://github.com/adityatelange/hugo-PaperMod themes/PaperMod --depth=1 生成public内容时清空文件夹 hugo -F --cleanDestinationDir 新建post hugo new content posts/my-first-post.md 完成Git push流程 echo "# showguan.github.io" >> README.md git init git add README.md git commit -m "first commit" git branch -M main git remote add origin https://github.com/showguan/showguan.github.io.git git push -u origin main git remote add origin https://github.com/showguan/showguan.github.io.git git branch -M main git push -u origin main 强制push到仓库 ...

2024-08-03 · 5 分钟 · 2444 字 · updated: 2024-09-01 · ShowGuan

Kotlin基础

Kotlin基础 val & var const 编译时常量只能在函数之外定义,因为编译时常量必须在编译时赋值, 而函数都是在运行时才调用, 函数内的变量也是在运行时赋值,编译时常量要在这些变量赋值前就已经存在。 函数参数 fun main(){ println(doSomething(1, false)) println(fix("Jack")) println(fix(age=10, name="Rose")) } private fun doSomething(age:Int, flag:Boolean):String{ return "result" } fun fix(name:String, age:Int = 2){ println(name + " " + age) } 函数没有返回类型时默认返回Unit ...

2024-08-03 · 12 分钟 · 5514 字 · updated: 2024-08-03 · ShowGuan

训练营第十二天笔记

第十二天笔记 SW 屏幕适配 Handler实现通信。 代码可维护,精简

2024-07-17 · 1 分钟 · 31 字 · updated: 2024-07-17 · ShowGuan

训练营第十一天笔记

第十一天笔记 Kotlin 讲义总结 1. 包的定义与导入 1) 包的声明 包的声明在代码文件的开头,格式为 package 包名。 包名是工程根目录下的子目录,如 com.jetbrains。 在根目录下创建 com.jetbrains 包,并在此包下创建 Demo1.kt 文件,文件第一行声明包名:package com.jetbrains。 2) 包的导入 ...

2024-07-16 · 7 分钟 · 3018 字 · updated: 2024-07-16 · ShowGuan

训练营第十天笔记

第十天笔记 内存泄漏 1. Java垃圾回收机制 1.1 什么是垃圾回收 垃圾回收(GC)是由Java虚拟机(JVM)垃圾回收器提供的一种内存回收机制。 当内存空间或内存占用过高时,系统会回收那些没有引用的对象。 JVM内存模型 运行时数据区域:包括方法区、堆、栈、本地方法栈和程序计数器等。 堆内存: 新生代(Young Generation):分为Eden区和两个Survivor区(S0、S1)。 老年代(Old Generation)。 方法区(MetaSpace):存储类元数据、方法信息等。 1.2 判断对象是否是垃圾的算法 1.2.1 引用计数算法 对象被创建后,系统为其初始化引用计数器。 每当对象被引用时,计数器加1,引用失效时,计数器减1。 当计数器为0时,对象不再被引用,可以进行回收。 优点:判断简单,效率高。 缺点:无法避免循环引用。 1.2.2 可达性分析法 从GC Roots出发,逐步遍历到所有可达的对象。 这些对象称为可达对象,不可达的对象则被标记为垃圾,需要回收。 GC Roots包括的对象: 虚拟机栈中引用的对象(栈帧中的本地变量表)。 方法区中类静态属性引用的对象。 方法区中常量引用的对象。 本地方法栈中JNI(Native方法)引用的对象。 Java中的对象引用 Java中的对象引用主要分为四种类型: ...

2024-07-15 · 3 分钟 · 1411 字 · updated: 2024-07-15 · ShowGuan

训练营第九天笔记

第九天笔记 权限与网络请求课程预习 1. 有哪些权限,具体权限的介绍 普通权限 网络权限:允许设备访问网络 <uses-permission android:name="android.permission.INTERNET" /> 获取网络的状态:如是否有网 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 读取手机状态:如IMEI等信息 <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 获取WiFi的状态 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 敏感权限 写入SD卡权限:文件下载、图片下载 ...

2024-07-14 · 7 分钟 · 3076 字 · updated: 2024-07-14 · ShowGuan

训练营第八天笔记

第八天笔记 自定义控件的实现 View 绘制过程 Activity 和 View 的关系 Window 类:负责在 Activity 中展示内容(具体实现为 PhoneWindow 类) DecorView:Window 创建出根布局 DecorView(继承自 FrameLayout) 单个 View 的绘制步骤 系统根据布局树完成界面绘制,单个 View 需要经过三个步骤: ...

2024-07-13 · 11 分钟 · 5173 字 · updated: 2024-07-13 · ShowGuan

训练营第七天笔记

第七天笔记 Android 动画 帧动画 作用对象 视图控件 (View) 例如 Android 的 TextView、Button 等等 不可作用于 View 组件的属性,如:颜色、背景、长度等等 使用 资源文件方式 代码方式 资源文件方式 基本信息介绍 ...

2024-07-12 · 3 分钟 · 1151 字 · updated: 2024-07-12 · ShowGuan

训练营第六天学习笔记

第六天笔记 组件库笔记 1. 组件库依赖、发布和使用 依赖方式对比 2.x版本 3.x版本 说明 apk runtimeOnly apk 功能同 runtimeOnly。只在生成 apk 时参与打包,编译时不会参与。Gradle 只会将依赖项添加到构建输出,以便在运行时使用。 provided compileOnly provided 功能同 compileOnly。只在编译时有效,不会参与打包至 apk。 compile api compile 功能同 api。该依赖方式会传递所依赖的库,当其他 module 依赖了该 module 时,可以使用该 module 下使用 api 依赖的库。 - implementation 该依赖方式所依赖的库不会传递,只会在当前 module 中生效。 格式介绍 格式 介绍 差异 AAR AAR 文件包含了 Android 库项目的代码、资源文件和清单文件等信息,可以被其他 Android 应用程序引用和使用。 Android 特有的归档文件格式,主要用于打包 Android 库项目。 JAR JAR 文件包含了 Java 类文件、资源文件和清单文件等信息,可以被其他 Java 应用程序引用和使用。 Java 中常用的归档文件格式,用于打包 Java 类库和应用程序。 依赖添加方式 本地依赖 ...

2024-07-11 · 6 分钟 · 2893 字 · updated: 2024-07-11 · ShowGuan

训练营第四天学习笔记

第四天笔记 Android UI 课程重点知识笔记 1. 了解Android控件常用属性 Android:id 任何 View 对象均可拥有与之关联的整型 ID,用于在结构树中对 View 对象进行唯一标识。 系统会以整型形式引用此 ID。 在布局 XML 文件中,系统通常以字符串的形式在 android:id 属性中指定该 ID。 // 使用系统资源 android:id="@android:id/androidView" // 使用自己创建的资源 android:id="@+id/myView" // 标识创建一个新资源 android:id="@id/myView" // 使用现有资源 android:layout_width 和 android:layout_height android:layout_width 和 android:layout_height 分别表示控件的宽度和高度。 取值为 wrap_content、match_parent 和具体的数值(如 40dp)。 wrap_content:表示控件宽度/高度由内容决定。 match_parent:表示控件宽度/高度为父view允许的最大值。 <View android:layout_width="wrap_content" // 设置宽 android:layout_height="wrap_content" // 设置高 /> 2. 了解文本框 TextView TextView 介绍 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center"> <TextView android:layout_width="wrap_content" // 设置文字 android:layout_height="wrap_content" android:background="@color/teal_200" // 设置背景颜色 android:text="Hello World" // 设置文本内容 android:textSize="20dp" // 设置文字大小 android:textColor="#FAFA02" // 设置文字颜色 android:textStyle="bold"/> // 设置文字样式(normal, bold, italic) </LinearLayout> 3. 了解按钮 Button Button 介绍 Button:在 UI 上生成一个按钮,用户点击时触发 onclick 事件。 ...

2024-07-10 · 4 分钟 · 1802 字 · updated: 2024-07-10 · ShowGuan

训练营第五天学习笔记

第五天笔记 Android 布局与优化 基本布局 公共属性 布局类型 共有属性 layout_gravity: 控件相对于父控件的对齐方式 gravity: 控件内部的对齐方式 padding: 内间距 paddingTop: 上间距 paddingBottom: 下间距 paddingLeft: 左间距 paddingRight: 右间距 layout_width: 控件的宽度 layout_height: 控件的高度 layout_margin: 外间距 layout_marginLeft: 控件的左间距 layout_marginRight: 控件的右间距 layout_marginTop: 控件的上间距 layout_marginBottom: 控件的下间距 示例代码 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="300dp" android:layout_height="300dp" android:layout_weight="1" android:gravity="bottom" android:text="AA" android:textSize="30sp" android:background="@color/colorPrimary" /> <TextView android:layout_width="200dp" android:layout_height="200dp" android:layout_weight="2" android:gravity="bottom" android:text="BB" android:textSize="30sp" android:background="@color/colorAccent" /> <TextView android:layout_width="100dp" android:layout_height="100dp" android:layout_weight="3" android:gravity="bottom" android:text="CC" android:textSize="30sp" android:background="@color/colorPrimaryDark" /> </FrameLayout> 基本布局 FrameLayout 特点:FrameLayout 允许子视图堆叠在一起,只显示最后添加的子视图。 示例代码 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="300dp" android:layout_height="300dp" android:layout_weight="1" android:gravity="bottom" android:text="AA" android:textSize="30sp" android:background="@color/colorPrimary" /> <TextView android:layout_width="200dp" android:layout_height="200dp" android:layout_weight="2" android:gravity="bottom" android:text="BB" android:textSize="30sp" android:background="@color/colorAccent" /> <TextView android:layout_width="100dp" android:layout_height="100dp" android:layout_weight="3" android:gravity="bottom" android:text="CC" android:textSize="30sp" android:background="@color/colorPrimaryDark" /> </FrameLayout> 效果:如右侧预览图所示,三个TextView控件堆叠在一起,显示最上层的控件内容。 LinearLayout 特点:LinearLayout 以线性排列子视图,可以设置为水平或垂直布局。 属性介绍 orientation:排列方式 horizontal:水平布局 vertical:垂直布局 layout_weight:权重 使用比例的方式来指定控件的大小 属性关系图 属性 ├─ orientation 排列方式 │ ├─ horizontal 水平布局 │ └─ vertical 垂直布局 └─ layout_weight 权重:使用比例的方式来指定控件的大小 以上为Android布局中的FrameLayout和LinearLayout的基本概念与属性介绍。 ...

2024-07-10 · 4 分钟 · 1940 字 · updated: 2024-07-10 · ShowGuan

训练营第三天学习笔记

第三天笔记 Fragment 重点知识总结 1. fragment背景 Fragment的诞生 引入版本: Android 3.0 (API 11) 背景和目的: 初衷是为了适应大屏幕的平板电脑,由于平板电脑的屏幕比手机屏幕更大,因此可以容纳更多的UI组件,且这些UI组件之间存在交互关系。 ...

2024-07-09 · 3 分钟 · 1097 字 · updated: 2024-07-09 · ShowGuan

训练营第二天学习笔记

第二天笔记 Android 四大组件课程概要总结 1. Activity a. 创建 自动创建 在新建项目后,会自动为我们创建一个 MainActivity。Activity 组成部分如下: 继承自 Activity 的类 放在 res/layout 文件夹的布局 XML 文件 在 AndroidManifest.xml 文件中声明 b. Activity 生命周期回调方法 ...

2024-07-08 · 9 分钟 · 4405 字 · updated: 2024-07-08 · ShowGuan

训练营第一天学习笔记

第一天学习笔记 老师:唐鸿程 Android按照运行方式分为3阶段 JIT AOT AOT+JIT Android系统可以分5层 kernel 层 ,硬件抽象层 , art c++层 , java framework层 , app层 字节码对齐(Bytecode Alignment):在 Android 应用开发中是一个优化步骤,旨在提高应用程序的启动速度和运行效率。它主要用于优化 DEX 文件的加载过程。 ...

2024-07-07 · 2 分钟 · 701 字 · updated: 2024-07-07 · ShowGuan
« 上一页  下一页  »
© 2026 Kennem's Blog · Powered by Hugo & PaperMod
👤 Visitors: 👀 Views: