PictureLoading.ets
875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Logger } from 'wdKit';
const TAG = 'PictureLoading';
@Component
export struct PictureLoading {
private imagePath: string = ''
//alt app.media.picture_loading 设计稿尺寸
@State imageWidth: string | number = 167
@State ratio: number = 167 / 60
async aboutToAppear() {
Logger.info(TAG, 'pictures preview')
}
build() {
Row() {
Image(this.imagePath)
.alt($r('app.media.picture_loading'))
.width(this.imageWidth)
.aspectRatio(this.ratio)
.objectFit(ImageFit.Fill)
.interpolation(ImageInterpolation.High)
.onComplete((event) => {
if (event) {
this.imageWidth = '100%'
this.ratio = event.width / event.height
}
})
}
.height('100%')
.width('100%')
.backgroundColor(Color.Black)
.justifyContent(FlexAlign.Center)
}
}