可以使用 @ohos.measure 中的接口 MeasureText 计算指定文本单行布局下的宽度,具体可参考如下代码:import { MeasureText } from '@kit.ArkUI' @Entry @Component struct Index { @State textWidth: number = MeasureText.measureText({ textContent: "Hello word", fontSize: '50px' }) build() { Row() { Column() { Text(`The width of 'Hello World': ${this.textWidth}`) } .width('100%') } .height('100%') } }参考链接:@ohos.measure (文本计算)
可以使用
@ohos.measure
中的接口MeasureText
计算指定文本单行布局下的宽度,具体可参考如下代码:参考链接:
@ohos.measure (文本计算)