最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - FlowRow not wrapping correctly - Stack Overflow

programmeradmin2浏览0评论

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):

发布评论

评论列表(0)

  1. 暂无评论