老套路先看图:PicuterShow/GIF 2021-12-31 18-26-59.gif · xiayiye5/ComposeStudy - Gitee.com
这里面涉及的知识点比较多主要有:
1.AS版本建议使用最新的白狐版本,注意compose目前仅支持kotlin语言开发
2.列表控件LazyColumn
3.compose如何加载网络图片
4.布局如何编写
第一步使用最新版本AS创建一个compose项目,创建后等待库下载完成会自定配置compose环境
第二步:得先依赖网络图片库
implementation("io.coil-kt:coil:1.4.0")
implementation("io.coil-kt:coil-compose:1.4.0")
第三步:
开始编写首页布局
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeStudyTheme {
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
Greeting()
}
}
}
}
}
@Composable
fun Greeting() {
//这个就是首页布局
HomeShow()
}
@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
ComposeStudyTheme {
Greeting()
}
}
再看下首页布局怎么样的
package com.example.composestudy.ui.widget
import android.widget.Toast
import androidx.comp