简体   繁体   English

Jetpack Compose:文本中断时在行中换行

[英]Jetpack Compose: New Line in Row when Text breaks

I have a Row which contains three other Rows - all of them with an image and a text.我有一个包含其他三个行的行 - 所有这些行都带有图像和文本。 Now the last row's text wraps into another line (just one letter).现在最后一行的文本换行到另一行(只有一个字母)。 That's not always the case as there are different Strings passed to the field but is there a way to say if this text begins to wrap, move it into another line?情况并非总是如此,因为有不同的字符串传递给字段,但是有没有办法说如果此文本开始换行,请将其移至另一行? I can't show code because it's work-related but I illustrated what I imagined it to look like我无法显示代码,因为它与工作相关,但我说明了我想象的样子

EDIT: Fixed it by using .lenght and moving stuff to another row if they're too long编辑:通过使用 .lenght 修复它并将内容移动到另一行,如果它们太长

A more elegant solution than checking the length of the elements is to use the Flow Layout , from the Accompanist library (as correctly pointed by @Philip Dukhov in the comments).比检查元素长度更优雅的解决方案是使用来自Accompanist库的Flow Layout (正如@Philip Dukhov 在评论中正确指出的那样)。

Unlike the standard Row and Column composables, these layout children across multiple rows/columns if they exceed the available space.与标准的 Row 和 Column 组合不同,这些布局子项跨越多行/列,如果它们超过可用空间。

Example of FlowRow FlowRow示例

FlowRow {
    repeat(30) {
        Box(
            modifier = Modifier
                .size(64.dp)
                .background(Color.Blue)
                .border(2.dp, Color.DarkGray),
            contentAlignment = Alignment.Center,
        ) {
            Text(it.toString())
        }
    }
}

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM