中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
一、事件 组件区域变化事件指组件显示的尺寸、位置等发生变化时触发的事件。(api8开始支持)
二、示例
代码:
@Entry @Component struct AreaExample { @State value: string = 'Text' @State sizeValue: string = '' build() { Column() { Text(this.value) .backgroundColor(Color.Gray).margin(30).fontSize(20).padding(4) .onClick(() => { this.value = this.value + ' | Text' }) .onAreaChange((oldValue: Area, newValue: Area) => { console.info(`Ace: on area change, oldValue is ${JSON.stringify(oldValue)} value is ${JSON.stringify(newValue)}`) this.sizeValue = JSON.stringify(newValue) }) Text('new area is: \n' + this.sizeValue).margin({ right: 30, left: 30 }) } .width('100%').height('100%').margin({ top: 30 }) } }
网站代码地址:https://gitee.com/jltfcloudcn/jump_to/tree/master/AreaChange
微信扫码分享