启动页面整体效果如下:
1,布局代码,头部一个logo 使用Image ,底部一个名称图片使用Image,最后一个描述是一个文本Text 组成
代码如下:
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center}){
Column() {
Image($r('app.media.ic_eshop'))
.width(100)
.aspectRatio(1)
.objectFit(ImageFit.Contain)
}
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Center)
.flexGrow(1)
Image($r('app.media.ic_title'))
.width($r('app.float.text_image_width'))
.height($r('app.float.text_image_height'))
.objectFit(ImageFit.Contain)
Text($r('app.string.splash_desc'))
.fontColor('#66000000')
.fontSize($r('app.float.bigger_font_size'))
.letterSpacing(16)
.margin({ top: $r('app.float.vp_twelve'), bottom: $r('app.float.splash_text_margin_bottom') })
}
.height('100%')
.width('100%')
.backgroundColor('#f1f3f5')
2,启动页进入下一页是自动进入,需要在aboutToAppear添加一个定时器,通过定时器定点时间做跳转,通过设置路由进入下一页 router.replaceUrl({ url: 'pages/MainPage' })
aboutToAppear() {
this.timeOutId = setTimeout(() => {
router.replaceUrl({ url: 'pages/MainPage' })
.catch((err: Error) => {
console.error(JSON.stringify(err));
})
}, 2000);
}
3,销毁定时器,在aboutToDisappear中销毁定时器
aboutToDisappear() {
clearTimeout(this.timeOutId);
}
4,完整代码如下
import router from '@ohos.router';
@Entry
@Component
struct Index {
private timeOutId: number = 0;
build() {
Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center}){
Column() {
Image($r('app.media.ic_eshop'))
.width(100)
.aspectRatio(1)
.objectFit(ImageFit.Contain)
}
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Center)
.flexGrow(1)
Image($r('app.media.ic_title'))
.width($r('app.float.text_image_width'))
.height($r('app.float.text_image_height'))
.objectFit(ImageFit.Contain)
Text($r('app.string.splash_desc'))
.fontColor('#66000000')
.fontSize($r('app.float.bigger_font_size'))
.letterSpacing(16)
.margin({ top: $r('app.float.vp_twelve'), bottom: $r('app.float.splash_text_margin_bottom') })
}
.height('100%')
.width('100%')
.backgroundColor('#f1f3f5')
}
aboutToAppear() {
this.timeOutId = setTimeout(() => {
router.replaceUrl({ url: 'pages/MainPage' })
.catch((err: Error) => {
console.error(JSON.stringify(err));
})
}, 2000);
}
aboutToDisappear() {
clearTimeout(this.timeOutId);
}
}
最后
如果你想快速提升鸿蒙技术,那么可以直接领取这份包含了:【OpenHarmony多媒体技术、Stage模型、ArkUI多端部署、分布式应用开发、音频、视频、WebGL、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战】等技术知识点。
鸿蒙Next全套VIP学习资料←点击领取!(安全链接,放心点击)
1.鸿蒙核心技术学习路线
2.大厂面试必问面试题
3.鸿蒙南向开发技术
4.鸿蒙APP开发必备
5.HarmonyOS Next 最新全套视频教程
6.鸿蒙生态应用开发白皮书V2.0PDF