gpt4 book ai didi

kotlin - Jetpack Compose Row - 绘制子元素 sibling

转载 作者:行者123 更新时间:2023-12-01 23:10:27 25 4
gpt4 key购买 nike

我有一个 LazyColumnRows 作为 child

我试图在与其他子项重叠的行元素之一上绘制一个圆圈,但该圆圈被绘制在 sibling 下方的左侧和底部

我曾尝试使用 Modifier.zIndex,但没有成功。

这是我所拥有的:

@Composable
fun HorizontalGrid() {
val days = (1..300).toList()
val weekChunks: List<List<Int>> = days.chunked(7)
LazyColumn {
items(weekChunks) { days: List<Int> ->
Week(days)
}
}
}

@Composable
fun Week(days: List<Int>) {
Row(horizontalArrangement = Arrangement.SpaceEvenly, modifier = Modifier.fillMaxSize()) {
days.forEach {
Day(it)
}
}
}

@Composable
fun Day(dayOfWeek: Int) {
Box(
modifier = Modifier
.size(48.dp)
.padding(4.dp)
.background(Color.LightGray)
) {
Text(
modifier = Modifier
.drawWithContent {
if (dayOfWeek == 17) {
drawContent()
drawCircle(Color.Gray, radius = 150F, center = Offset(50f, 50f))
}
},
text = dayOfWeek.toString()
)
}
}

这是我得到的:

enter image description here

我需要的是圆圈覆盖所有正方形。

最佳答案

有两个地方需要添加zIndex

代码

@Composable
fun HorizontalGrid() {
val days = (1..300).toList()
val weekChunks: List<List<Int>> = days.chunked(7)
LazyColumn {
items(items = weekChunks) { days: List<Int> ->
Week(days)
}
}
}

@Composable
fun Week(days: List<Int>) {
Row(
horizontalArrangement = Arrangement.SpaceEvenly,
modifier = Modifier
.fillMaxSize()
.zIndex(if (days.contains(17)) 2f else 1f)
) {
days.forEach {
Day(it)
}
}
}

@Composable
fun Day(dayOfWeek: Int) {
Box(
modifier = Modifier
.zIndex(if (dayOfWeek == 17) 2f else 1f)
.size(48.dp)
.padding(4.dp)
.background(Color.LightGray)
) {
Text(
modifier = Modifier
.drawWithContent {
if (dayOfWeek == 17) {
drawContent()
drawCircle(Color.Gray, radius = 150F, center = Offset(50f, 50f))
}
},
text = dayOfWeek.toString()
)
}
}

结果

enter image description here

关于kotlin - Jetpack Compose Row - 绘制子元素 sibling ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70023676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com