当前位置:   article > 正文

纯血鸿蒙APP开发实战—启动页面_鸿蒙启动页

鸿蒙启动页

启动页面整体效果如下:

图片

1,布局代码,头部一个logo 使用Image ,底部一个名称图片使用Image,最后一个描述是一个文本Text 组成

代码如下:

  1. Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center}){
  2. Column() {
  3. Image($r('app.media.ic_eshop'))
  4. .width(100)
  5. .aspectRatio(1)
  6. .objectFit(ImageFit.Contain)
  7. }
  8. .justifyContent(FlexAlign.Center)
  9. .alignItems(HorizontalAlign.Center)
  10. .flexGrow(1)
  11. Image($r('app.media.ic_title'))
  12. .width($r('app.float.text_image_width'))
  13. .height($r('app.float.text_image_height'))
  14. .objectFit(ImageFit.Contain)
  15. Text($r('app.string.splash_desc'))
  16. .fontColor('#66000000')
  17. .fontSize($r('app.float.bigger_font_size'))
  18. .letterSpacing(16)
  19. .margin({ top: $r('app.float.vp_twelve'), bottom: $r('app.float.splash_text_margin_bottom') })
  20. }
  21. .height('100%')
  22. .width('100%')
  23. .backgroundColor('#f1f3f5')

2,启动页进入下一页是自动进入,需要在aboutToAppear添加一个定时器,通过定时器定点时间做跳转,通过设置路由进入下一页 router.replaceUrl({ url: 'pages/MainPage' })

  1. aboutToAppear() {
  2. this.timeOutId = setTimeout(() => {
  3. router.replaceUrl({ url: 'pages/MainPage' })
  4. .catch((err: Error) => {
  5. console.error(JSON.stringify(err));
  6. })
  7. }, 2000);
  8. }

3,销毁定时器,在aboutToDisappear中销毁定时器

  1. aboutToDisappear() {
  2. clearTimeout(this.timeOutId);
  3. }

4,完整代码如下

  1. import router from '@ohos.router';
  2. @Entry
  3. @Component
  4. struct Index {
  5. private timeOutId: number = 0;
  6. build() {
  7. Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center}){
  8. Column() {
  9. Image($r('app.media.ic_eshop'))
  10. .width(100)
  11. .aspectRatio(1)
  12. .objectFit(ImageFit.Contain)
  13. }
  14. .justifyContent(FlexAlign.Center)
  15. .alignItems(HorizontalAlign.Center)
  16. .flexGrow(1)
  17. Image($r('app.media.ic_title'))
  18. .width($r('app.float.text_image_width'))
  19. .height($r('app.float.text_image_height'))
  20. .objectFit(ImageFit.Contain)
  21. Text($r('app.string.splash_desc'))
  22. .fontColor('#66000000')
  23. .fontSize($r('app.float.bigger_font_size'))
  24. .letterSpacing(16)
  25. .margin({ top: $r('app.float.vp_twelve'), bottom: $r('app.float.splash_text_margin_bottom') })
  26. }
  27. .height('100%')
  28. .width('100%')
  29. .backgroundColor('#f1f3f5')
  30. }
  31. aboutToAppear() {
  32. this.timeOutId = setTimeout(() => {
  33. router.replaceUrl({ url: 'pages/MainPage' })
  34. .catch((err: Error) => {
  35. console.error(JSON.stringify(err));
  36. })
  37. }, 2000);
  38. }
  39. aboutToDisappear() {
  40. clearTimeout(this.timeOutId);
  41. }
  42. }

最后

如果你想快速提升鸿蒙技术,那么可以直接领取这份包含了:【OpenHarmony多媒体技术、Stage模型、ArkUI多端部署、分布式应用开发、音频、视频、WebGL、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战】等技术知识点。

鸿蒙Next全套VIP学习资料←点击领取!(安全链接,放心点击

1.鸿蒙核心技术学习路线

2.大厂面试必问面试题

3.鸿蒙南向开发技术

 4.鸿蒙APP开发必备

 5.HarmonyOS Next 最新全套视频教程

 6.鸿蒙生态应用开发白皮书V2.0PDF

这份全套完整版的学习资料已经全部打包好,朋友们如果需要可以点击 鸿蒙Next全套VIP学习资料免费领取(安全链接,放心点击

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/956150
推荐阅读
相关标签
  

闽ICP备14008679号