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