折叠屏展开和折叠屏幕修改显示的图片宽高时,Image图片显示没有根据变更的宽高刷新
代码片段:
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
photoSaveViewModel: PhotoSaveViewModel = new PhotoSaveViewModel()
build() {
RelativeContainer() {
Image($r('app.media.test_photo'))
.width(this.photoSaveViewModel.imageViewWidth)
.height(this.photoSaveViewModel.imageViewHeight)
.interpolation(ImageInterpolation.High)
.margin({
top: this.photoSaveViewModel.imageViewTopMargin,
bottom: this.photoSaveViewModel.imageViewBottomMargin,
left: this.photoSaveViewModel.imageViewLeftMargin,
right: this.photoSaveViewModel.imageVIewRightMargin
})
.draggable(false)
.alignRules({
middle:{anchor:"__container__",align:HorizontalAlign.Center},
top: { anchor: "__container__", align: VerticalAlign.Top }
})
}
.height('100%')
.width('100%')
}
}
参考如下写法
Index.ets 改成下面这样