场景一:使用onAreaChange监听组件的尺寸变化,把右边控件的高度赋值给左边控件的高度。@Entry
@Component
struct MyComponent {
@State bHeight: string = 'auto';
build() {
Column() {
Row() {
Text('A')
.height(this.bHeight)
.backgroundColor('#5291FF');
Text('B 组件区域变化事件:组件区域变化事件指组件显示的尺寸、位置等发生变化时触发的事件。')
.height('auto')
.onAreaChange((oldValue: Area, newValue: Area) => {
console.info(`${oldValue}`);
this.bHeight = `${newValue.height}`;
})
.backgroundColor('#61CFBE');
}
.width('90%')
.height('auto');
}
.height('100%')
.width('100%')
.justifyContent(FlexAlign.Center);
}
}