admin管理员组文章数量:1389754
I'm usign a FlowRow
to display a variable number of buttons with variable text and an Icon, as you can see in the screenshot below, the button with "enter the room" text is not displaying the icon. this is due to lack of space, if I reduce the font size it's displayed correctly. In this situation I would like the button to go to the next row. I don't think it's FlowRow
's fault, rather the Row
in the button is measuring its children one by one and the text is not constrained, leaving no space for the icon. How can I solve it?
FlowRow(
horizontalArrangement = Arrangement.spacedBy(
2.dp,
Alignment.CenterHorizontally
),
verticalArrangement = Arrangement.spacedBy(
2.dp,
Alignment.CenterVertically
),
maxItemsInEachRow = 3,
overflow = FlowRowOverflow.Visible,
) {
Chip(
text = "enter the room",
icon = R.drawable.ic_wallet,
onClick = { },
modifier = Modifier.weight(1f)
)
//more chips like this }
@Composable
private fun Chip(
text: String,
@DrawableRes icon: Int,
onClick: () -> Unit,
modifier: Modifier = Modifier,
hasBalloon: Boolean = false,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = modifier
.background(
shape = RoundedCornerShape(CornerSize(8.dp)),
color = Color.Grey
)
.rippleClickable(onClick = onClick)
.padding(4.dp)
) {
Text(
text,
maxLines = 1,
textAlign = TextAlign.Center,
overflow = TextOverflow.Ellipsis,
)
Box(
modifier = Modifier
.padding(start = 4.dp)
.size(16.dp)
) {
GlideImage(
model = icon,
transition = CrossFade,
contentDescription = "",
contentScale = ContentScale.Fit,,
)
if (hasBalloon) {
Box(
modifier = Modifier
.width(7.dp)
.height(7.dp)
.background(shape = CircleShape, color = Colors.Red)
.align(Alignment.TopEnd)
)
}
}
}
Changing Box
's size(16.dp)
with
.fillMaxHeight()
.aspectRatio(1f)
results in the icon overlapping the text (and Row
's padding):
本文标签: androidFlowRow not wrapping correctlyStack Overflow
版权声明:本文标题:android - FlowRow not wrapping correctly - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744666270a2618551.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论