我想这样划
- 预期产出**
以及
我试过这段代码
- 带项目的除数**
@Composable
fun DividerWithItem(
modifier: Modifier = Modifier,
index: () -> Int,
itemName: String,
lastIndex: () -> Int,
moreRowContent: @Composable RowScope.() -> Unit,
) {
Column {
if (index() == 0) {
Divider(color = Cloudy, thickness = dimensionResource(R.dimen.separator_height_width))
}
Row(
modifier = modifier,
horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = itemName,
modifier = Modifier.padding(vertical = 12.dp),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
moreRowContent()
}
if (index() <= lastIndex()) {
Divider(color = Cloudy, thickness = 1.dp)
}
}
}
- 血压选项标签**
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun LazyItemScope.BpmOptionsLabel(
index: () -> Int,
optionName: String,
lastIndex: () -> Int
) {
DividerWithItem(
modifier = Modifier
.fillMaxSize()
.animateItemPlacement(),
index = index,
itemName = optionName,
lastIndex = lastIndex
) {
Image(
modifier = Modifier.weight(.3f),
painter = painterResource(R.drawable.ic_menu),
contentDescription = null,
)
}
}
- 血压选项标签预览**
@Preview(showBackground = true)
@Composable
fun BpmOptionsLabelPreview() {
LazyColumn {
item {
BpmOptionsLabel(
index = { 0 },
"Item item item item item m 1",
lastIndex = { 1 }
)
}
}
}
- 实际产量**
唯一的问题是Text
和Image
项目位置不正确
2条答案
按热度按时间sycxhyv71#
在
DividerWithItem
中,将weight(1f)
应用于Text
并在
LazyItemScope.BpmOptionsLabel
中从Image
中删除weight
修饰符:如果要增加图像占用的空间,请使用
padding
修改器:uhry853o2#
你可以试试这个,只要增加文本的重量,图像就会根据它的大小按照它需要的剩余大小。
结果: