列表在普遍App中是一个十分重要组成部分,随处可见,而在Compose中是如何实现列表的呢?没错,就是使用LazyColumn实现纵向滚动列表,使用LazyRow实现横向滚动列表,下面是一个简单的例子。
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
/**
* 列表
*/
class Compose_08Activity : Compon

本文介绍了在Android Compose中如何使用LazyColumn和LazyRow创建纵向和横向滚动列表。通过设置contentPadding可以为内容添加内边距,利用Arrangement.spacedBy()方法可以在列表项之间添加间距。

2686

被折叠的 条评论
为什么被折叠?



