[英]Jetpack Compose: Center Icon or Trailing elements in a ListItem
I'm trying to center the icon and trailing elements vertically using a ListItem.我正在尝试使用 ListItem 将图标和尾随元素垂直居中。 I'm not sure if it is possible or I need to drop the ListItem and use a combination of column/row instead.
我不确定是否有可能,或者我需要删除 ListItem 并改用列/行的组合。
I'm using something like:我正在使用类似的东西:
ListItem(
Modifier.clickable(onClick = onClick),
icon = {
Box(
modifier = Modifier.fillMaxHeight(), contentAlignment = ALignment.Center
) {
Text(
text = dateUtil.formatTime(item.startTime),
style = TextStyle(
color = SnyDarkBlue,
fontSize = 14.sp,
fontFamily = oswaldFamily,
fontWeight = FontWeight.Bold,
letterSpacing = (-0.25).sp,
),
)
}
},
thanks in advance!提前致谢!
You can center both the icon and text sections using a Column:您可以使用 Column 将图标和文本部分居中:
ListItem(
modifier = Modifier
.fillMaxWidth()
.requiredHeight(50.dp)
.background(color = Color.Gray),
icon = {
Column(
modifier = Modifier
.fillMaxHeight(), verticalArrangement = Arrangement.Center
) {
Text(
text = "06:00 PM"
)
}
},
text = {
Column(
modifier = Modifier
.fillMaxHeight(), verticalArrangement = Arrangement.Center
) {
Text("Your item text goes here")
}
},
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.