Compose
赶鸭子上架,要写一个简单的列表页面,第二天提测,今天开始入门compose。看看怎么快速入门(面向应用学习)吧!
略读官方文档
引用自https://developer.android.google.cn/jetpack/compose/architecture
-
单向数据流的设计模式
-
将现有布局迁移到 Compose,可以将 View 替换为保留了相同布局参数和 id 的 ComposeView:
<...> <!-- Other content --> <androidx.compose.ui.platform.ComposeView android:id="@+id/greeting" android:layout_width="match_parent" android:layout_height="wrap_content"/> </...>
然后,在使用了该 XML 布局的 Activity 或 Fragment 中,我们可以获取 ComposeView,并调用 setContent 方法,以向其中添加 Compose 内容。
学习(阅读理解)同事代码
-
同样使用MVVM架构,将Fragment中的View替换为ComposeView。
-
列表使用LazyColumn,官方注释:
The vertically scrolling list that only composes and lays out the currently visible items. The content block defines a DSL which allows you to emit items of different types. For example you can use LazyListScope.item to add a single item and LazyListScope.items to add a list of items.
仅组成和布置当前可见项目的垂直滚动列表。内容块定义了一个 DSL,它允许您发出不同类型的项目。例如,您可以使用 LazyListScope.item 添加单个项目,并使用 LazyListScope.items 添加项目列表。因为只针对当前可见项,所以可以直接在
itemsIndexed()
函数中写exposure曝光埋点函数不需要监听滑动状态。
参考
Jetpack Compose学习之mutableStateOf与remember是什么
然后我开始写了先
long
long
time
later
.
.
.
等更新😵💫
发现csdn新手引导里好多图的写法好好玩
甘特图👇