如下面的代码,目的是当事件来了后,改变xComponent的with,但发现通过下面的 incomingMsg 把size改成100%后,xComponent的大小没有改变。
private surfaceId : string =''
@State width: string="50%"
xcomponentController: XComponentController = new XComponentController()
build() {
Row() {
XComponent({
id: 'xcomponent',
type: 'surface',
controller: this.xcomponentController
})
.onLoad(() => {
this.xcomponentController.setXComponentSurfaceSize({surfaceWidth:1920,surfaceHeight:1080});
this.surfaceId = this.xcomponentController.getXComponentSurfaceId()
})
.width(this.width)
.height('480px')
}
.backgroundColor(Color.Black)
.position({x: 0, y: 48})
}
incomingMsg():void {
if(width_ == '100%') {
width_ = '50%'
} else {
width_ = '100%'
}
} |