我正在尝试 Jetpack Compose,但 Row 的行为让我感到困惑。我在图标按钮旁边有一个文本,我希望图标按钮锚定到最小宽度为 48dp 的一侧,并让文本环绕它。像这样:
但文本不会换行,它会占用行中的所有空间:
@Composable
fun SampleLayout(text: String) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
) {
Text(text)
IconButton(
onClick = { },
) {
Icon(
imageVector = androidx.compose.material.icons.Icons.Default.StarBorder,
null
)
}
}
}
@Preview(showBackground = true, backgroundColor = 0x006EAEA0, fontScale = 1.5F)
@Composable
fun SamplePreview1() {
Box(Modifier.padding(16.dp)) {
SampleLayout("helooooo")
}
}
@Preview(showBackground = true, backgroundColor = 0x006EAEA0, fontScale = 1.5F)
@Composable
fun SamplePreview2() {
Box(Modifier.padding(16.dp)) {
SampleLayout("helooooooooooooooooooooooooooo")
}
}
@Preview(showBackground = true, backgroundColor = …Run Code Online (Sandbox Code Playgroud)