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

567 篇文章 9 订阅
555 篇文章 1 订阅

启动页面整体效果如下:

图片

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>