我试图将Jetpack Compose中Text
组件内的内容居中,但我没有成功。虽然我很新手,但代码看起来没问题。以下是代码:
Row(
modifier = Modifier
.padding(8.dp)
.height(30.dp)
.fillMaxHeight(),
) {
IconButton(..) {..}
Spacer(modifier = Modifier.width(4.dp))
Text(
text = "Some text",
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxHeight()
.border(1.dp, Color.Black, RoundedCornerShape(20))
.width(120.dp)
.background(color = Color.White, RoundedCornerShape(20))
.align(Alignment.CenterVertically)
)
Spacer(modifier = Modifier.width(4.dp))
IconButton(..) {..}
}
这将产生以下结果:
![enter image description here](https://istack.dev59.com/JGU4g.webp)
Text
中,这在我看来相当奇怪。 - daniyelpBox
将文本居中于边框内,或让你的Row
根据内容大小自动换行。 - Phil Dukhov