Files
kmp-mini-shopping/docs/UI_参考资料_Android.md
T
xiaobai 7e5251a809
Build Android app / Build (push) Has been cancelled
Build iOS app / Build (push) Has been cancelled
Template Cleanup / Template Cleanup (push) Has been cancelled
docs(course): include intros and separate UI material for students
2026-03-04 21:06:39 +08:00

100 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# KMP Mini Shopping UI 参考资料(Android)
> 本资料用于配套第6/第7节课件,课堂不要求逐行敲 UI,可作为对照与课后复现参考。
---
## 1. 对应文件
- 主 UI:`composeApp/src/androidMain/kotlin/com/example/minishop/App.kt`
- ViewModel:`composeApp/src/androidMain/kotlin/com/example/minishop/ShopViewModel.kt`
- 默认封面图:`composeApp/src/androidMain/res/drawable/course_cover_default.xml`
---
## 2. 当前 UI 功能清单
1. 首页:两列瀑布流商品卡片(图/标题/价格/简介/加购)
2. 详情:商品图 + 标题 + 价格 + 描述 + 加购
3. 购物车:数量增减、移除、清空、结算
4. 购物车底部固定结算栏(总件数/总价)
5. 图片加载失败本地兜底
6. 搜索过滤(含 trim 处理)
---
## 3. UI 结构示意
```text
App()
├─ Scaffold
│ ├─ TopAppBar
│ ├─ BottomBar(Tab: Home/Cart)
│ └─ Content
│ ├─ ProductListScreen (Home)
│ ├─ ProductDetailScreen (Detail)
│ └─ CartScreen (Cart)
```
---
## 4. 核心 UI 片段(可复制)
### 4.1 两列瀑布流列表
```kotlin
LazyVerticalStaggeredGrid(
columns = StaggeredGridCells.Fixed(2),
verticalItemSpacing = 10.dp,
horizontalArrangement = Arrangement.spacedBy(10.dp)
) {
staggeredItems(products, key = { it.id }) { p ->
// 商品卡片
}
}
```
### 4.2 购物车底部固定结算栏
```kotlin
Box(Modifier.fillMaxSize()) {
LazyColumn(contentPadding = PaddingValues(bottom = 96.dp)) {
// 购物车项
}
Card(
modifier = Modifier
.align(Alignment.BottomCenter)
.fillMaxWidth()
) {
// 总件数 + 合计 + 清空 + 结算
}
}
```
### 4.3 图片加载失败兜底
```kotlin
SubcomposeAsyncImage(
model = url,
loading = { LocalFallbackImage() },
error = { LocalFallbackImage() },
success = { SubcomposeAsyncImageContent() }
)
```
---
## 5. 与第6/第7节的关系
- 第6节:重点是 shared 网络/存储链路,UI 只做最小调用
- 第7节:重点是 MVVM + 全流程整合,UI 以本资料为参考目标
---
## 6. 课堂建议
1. 课堂主线先讲 shared 和 MVVM,不在 UI 细节耗时
2. UI 细节(布局、样式、兜底)放到本资料供课后复现
3. 学员如果提前完成主线,可按本资料做 UI 进阶