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

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

阅读 559
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)
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进