中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
微信扫码分享
import componentUtils from '@ohos.arkui.componentUtils' @Entry @Component struct Index { @State textWidth: number = 0; @State textHeight: number = 0; build() { Column({space:20}) { Text('我是Text组件') .height(50) .backgroundColor(Color.Gray) .fontColor(Color.White) .id('text') // 设置id Button('Text的大小') .onClick(()=>{ let info = componentUtils.getRectangleById('text') this.`textWidth` = info.size.width this.`textHeight` = info.size.height console.log(JSON.stringify(info)) }) Text('宽度:'+this.`textWidth`+',高度:'+this.`textHeight`) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) } }