FloatingX 开源项目使用教程
1. 项目的目录结构及介绍
FloatingX 项目的目录结构如下:
FloatingX/
├── app/
│ ├── build.gradle
│ ├── src/
│ │ ├── main/
│ │ │ ├── java/
│ │ │ │ └── com/
│ │ │ │ └── petterpx/
│ │ │ │ └── floatingx/
│ │ │ │ └── MainActivity.kt
│ │ │ ├── res/
│ │ │ └── AndroidManifest.xml
├── floatingx/
│ ├── build.gradle
│ ├── src/
│ │ ├── main/
│ │ │ ├── java/
│ │ │ │ └── com/
│ │ │ │ └── petterpx/
│ │ │ │ └── floatingx/
│ │ │ │ ├── core/
│ │ │ │ ├── helper/
│ │ │ │ ├── listener/
│ │ │ │ ├── scope/
│ │ │ │ └── utils/
│ │ │ ├── res/
│ │ │ └── AndroidManifest.xml
├── build.gradle
├── settings.gradle
└── README.md
目录结构介绍
-
app/: 示例应用模块,包含项目的示例代码和资源文件。
- build.gradle: 示例应用的构建配置文件。
- src/main/java/com/petterpx/floatingx/MainActivity.kt: 示例应用的主活动文件。
- src/main/res/: 示例应用的资源文件。
- src/main/AndroidManifest.xml: 示例应用的清单文件。
-
floatingx/: 悬浮窗库模块,包含悬浮窗的核心实现和相关工具类。
- build.gradle: 悬浮窗库的构建配置文件。
- src/main/java/com/petterpx/floatingx/: 悬浮窗库的源代码目录。
- core/: 悬浮窗的核心实现类。
- helper/: 悬浮窗的辅助工具类。
- listener/: 悬浮窗的事件监听器。
- scope/: 悬浮窗的作用域管理类。
- utils/: 悬浮窗的工具类。
- src/main/res/: 悬浮窗库的资源文件。
- src/main/AndroidManifest.xml: 悬浮窗库的清单文件。
-
build.gradle: 项目的根构建配置文件。
-
settings.gradle: 项目的设置文件。
-
README.md: 项目的说明文档。
2. 项目的启动文件介绍
FloatingX 项目的启动文件是 MainActivity.kt
,位于 app/src/main/java/com/petterpx/floatingx/
目录下。
MainActivity.kt
package com.petterpx.floatingx
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
启动文件介绍
- MainActivity.kt: 这是示例应用的主活动文件,继承自
AppCompatActivity
。在onCreate
方法中,设置了布局文件activity_main
。
3. 项目的配置文件介绍
FloatingX 项目的配置文件主要包括 build.gradle
和 AndroidManifest.xml
。
build.gradle
根目录下的 build.gradle
// 根目录下的 build.gradle
buildscript {
ext.kotlin_version = '1.5.21'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}