文本组件多行显示有问题。已经设置了居中,但还是没有居中。代码如下:
@Entry
@Component
struct TextDemo {
build() {
Column() {
Text('已关注,\n成为珍爱粉哈哈')
.fontSize(9)
.maxLines(2)
.fontWeight(FontWeight.Medium)
.fontColor(Color.Black)
.align(Alignment.Center)
}
.backgroundColor(Color.Red)
.width(90)
.height(24)
}
}
text的align结合TextAlign属性可控制内容在水平方向的位置。参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-text-V5\#textalign
demo如下: