Jetpack Compose:行中多行文本,具有粗细和换行文本内容

问题描述 投票:0回答:1

我有一个

Row
布局,里面有两个可组合项:

  • Text
    当内容很长时,应该包裹自己的宽度并占用尽可能多的空间
  • Image
    每次都必须出现在
    Text
  • 的右侧

为了实现这两个目标,我目前正在使用

weight(weight = 1f, fill = false)
作为
Text
可组合项。它对于单行内容效果很好。但是,它会产生换行和换行多行文本的问题。为了看得更清楚,我添加了
background(Color.Yellow)
和一些长词。参见参考代码:

Row {
    Text(
        text = "This is the message with quite super-unprecedented words",
        modifier = Modifier
            .background(Color.Yellow)
            .weight(
                weight = 1f,
                fill = false
            )
    )

    Image(
        painter = painterResource(R.drawable.image),
        contentDescription = null
    )
}

结果如下所示:

是否可以删除

Text
末尾的填充,以便在多行情况下
Image
也可以与
Text
紧密贴合?或者有其他想法如何实现这一目标?我已经查看了
softWrap
Text
参数和
requireSize
Image
,但运气不佳。

android android-jetpack-compose
1个回答
0
投票

现在您可以通过应用换行属性并将文本样式的严格性设置为宽松来实现此目的。

 style = MaterialTheme.typography.bodySmall.copy(
                fontSize = 8.sp,
                lineBreak = LineBreak.Paragraph.copy(strictness = LineBreak.Strictness.Loose)
            )
© www.soinside.com 2019 - 2024. All rights reserved.