目前启动页展示整页图片只能使用与屏幕大小相同的图片,可以依照屏幕尺寸设置一个相同尺寸的图片,尺寸可以使用代码获取参数。具体代码见下:
import { display} from '@kit.ArkUI';
@Entry
@Component
struct Splash {
@State screenWidth: number = 0;
@State screenHeight: number = 0;
@State screenWidth2: number = 0;
@State imageResource: Resource = $r('app.media.startIcon');
aboutToAppear(): void {
let displayClass: display.Display | null = null;
displayClass = display.getDefaultDisplaySync();
this.screenWidth = displayClass.width;
this.screenHeight = displayClass.height;
console.log('width = ' + this.screenWidth + 'height = ' + this.screenHeight);
}
build() {
Column() {
Image(this.imageResource) // 启动图路径需替换成自定义的资源路径
.width('100%')
.height('100%')
.syncLoad(true); // 设置图片为同步加载
}
.width('100%')
.height('100%')
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
.backgroundColor(Color.White)
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Center);
}
}