HarmonyOS Text显示固定为2行,且高度随字体变化?

如题:HarmonyOS Text显示固定为2行,且高度随字体变化?

阅读 560
1 个回答

maxlines结合容器布局可实现效果,参考:

Row({ space: 10 }) {
  Column({ space: 10 }) {
    Image($r('app.media.img1')).width(100).height(100).objectFit(ImageFit.Fill)
    Text('我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字')
      .fontWeight(FontWeight.Bold)
      .maxLines(2)
  }
  .width(100)

  Column({ space: 10 }) {
    Image($r('app.media.img1')).width(100).height(100).objectFit(ImageFit.Fill)
    Text('我是文字')
      .fontWeight(FontWeight.Bold)
      .maxLines(2)
  }
  .width(100)
}
.alignItems(VerticalAlign.Top)
.width('100%')
.backgroundColor(Color.Pink)