ToB企服应用市场:ToB评测及商务社交产业平台
标题:
纯血鸿蒙APP开辟实战—启动页面
[打印本页]
作者:
金歌
时间:
2024-8-21 11:41
标题:
纯血鸿蒙APP开辟实战—启动页面
启动页面整体结果如下:
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@Componentstruct 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学习资料
→
免费领取(安全链接,放心点击
)
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/)
Powered by Discuz! X3.4