我试图在 jetpack compose 中将文本垂直居中,但基线始终从图标底部开始,我不明白为什么。
元素行已经设置了verticalAlignment = Alignment.CenterVertically,我已经尝试了文本和图标上几乎所有其他对齐方式的组合,此时我陷入了困境。这是代码的当前状态
AnimatedVisibility(visible = expanded) {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(
modifier = modifier
.padding(5.dp),
imageVector = Icons.Default.Email,
contentDescription = "email icon"
)
Text(
text = state.email
)
}
}
我认为,
includeFontPadding
导致了这一点。如果你设置includeFontPadding为false,你就可以达到你想要的
Text(
text = "[email protected]",
style = TextStyle(platformStyle = PlatformTextStyle(includeFontPadding = false))
)