鸿蒙OS开发:【一次开发,多端部署】(app市场首页)项目

一多应用市场首页

介绍

本示例展示了应用市场首页,页面中包括Tab栏、运营横幅、精品应用、精品游戏等。

本示例使用一次开发多端部署中介绍的自适应布局能力和响应式布局能力进行多设备(或多窗口尺寸)适配,保证应用在不同设备或不同窗口尺寸下可以正常显示。

用到了媒体查询接口[@ohos.mediaquery]

效果预览

本示例在预览器中的效果:

image.png

本示例在开发板上运行的效果:

image.png

使用说明:

  1. 启动应用,可以查看本应用在全屏状态下的显示效果。
  2. 在应用顶部,下滑出现窗口操作按钮。(建议通过外接鼠标操作,接入鼠标只需要将鼠标移动至顶部即可出现窗口)
  3. 点击悬浮图标,将应用悬浮在其它界面上显示。
  4. 拖动应用悬浮窗口的边框,改变窗口尺寸,触发应用刷新,即可查看应用在不同窗口下的显示效果。
  5. 改变窗口尺寸的过程中,窗口尺寸可能超出屏幕尺寸。此时在屏幕中只能看到应用部分区域的显示,但可以通过移动窗口位置,查看应用其它区域的显示。
  6. 开发前请熟悉鸿蒙开发指导文档:gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md点击或者复制转到。

工程目录

AppMarket/entry/src/main/ets/
|---model
|   |---HomeData.ets                       // 主页用到的图片资源
|   |---HomeDataType.ets                   // 事件监听函数
|---pages                                  
|   |---index.ets                          // 首页
|---common                                    
|   |---BreakpointSystem.ets               // 媒体查询
|   |---Home.ets                           // 主容器
|   |---IndexApps.ets                      // app模块(包含安装,展示图片,更多功能)
|   |---IndexContent.ets                   // 内容模块
|   |---IndexEntrance.ets                  // 下一步模块(箭头跳转组件)
|   |---IndexHeader.ets                    // 头部组件
|   |---IndexSwiper.ets                    // 轮播图   
|   |---TabBarItem.ets                     // 导航栏                                            

具体实现

本示例介绍如何使用自适应布局能力和响应式布局能力适配不同尺寸窗口,将页面分拆为5个部分。

底部/侧边导航栏

1、在sm和md断点下,导航栏在底部;在lg断点下,导航栏在左侧。
2、通过Tab组件的barPosition和vertical属性控制TabBar的位置在主轴方向起始或结尾位置和水平或垂直方向,同时还可以通过barWidth和barHeight属性控制TabBar的尺寸,[源码参考]。

/** Copyright (c) 2022 Huawei Device Co., Ltd.* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/import Home from '../common/Home'import TabBarItem from '../common/TabBarItem'import BreakpointSystem from '../common/BreakpointSystem'@Entry@Componentstruct Index {@State currentIndex: number = 0@StorageProp('currentBreakpoint') currentBreakpoint: string = 'md'private breakpointSystem: BreakpointSystem = new BreakpointSystem()private onTabChange = (index: number) => {this.currentIndex = index}aboutToAppear() {this.breakpointSystem.register()}aboutToDisappear() {this.breakpointSystem.unregister()}@BuildertabItem(index: number, title: Resource, icon: Resource, iconSelected: Resource) {TabBarItem({index: index,currentIndex: this.currentIndex,title: title,icon: icon,iconSelected: iconSelected})}build() {Tabs({ barPosition: this.currentBreakpoint === 'lg' ? BarPosition.Start : BarPosition.End }) {TabContent() {Home()}.tabBar(this.tabItem(0, $r('app.string.tabBar1'), $r('app.media.ic_home_normal'), $r('app.media.ic_home_actived')))TabContent() {}.tabBar(this.tabItem(1, $r('app.string.tabBar2'), $r('app.media.ic_app_normal'), $r('app.media.ic_app_actived')))TabContent() {}.tabBar(this.tabItem(2, $r('app.string.tabBar3'), $r('app.media.ic_game_normal'), $r('app.media.ic_mine_actived')))TabContent() {}.tabBar(this.tabItem(3, $r('app.string.tabBar4'), $r('app.media.ic_search_normal'), $r('app.media.ic_search_actived')))TabContent() {}.tabBar(this.tabItem(4, $r('app.string.tabBar4'), $r('app.media.ic_mine_normal'), $r('app.media.ic_mine_actived')))}.barWidth(this.currentBreakpoint === 'lg' ? 96 : '100%').barHeight(this.currentBreakpoint === 'lg' ? '60%' : 56).vertical(this.currentBreakpoint === 'lg').onChange(this.onTabChange).backgroundColor('#F1F3F5')}}
标题栏与搜索栏

通过栅格实现标题栏和搜索栏:在sm和md断点下分两行显示,在lg断点下单行显示,[源码参考]。

/** Copyright (c) 2022 Huawei Device Co., Ltd.* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/@Componentexport default struct IndexHeader {@StorageProp('currentBreakpoint') currentBreakpoint: string = 'md'@Builder searchBar() {Stack({alignContent: Alignment.End}) {TextInput({ placeholder: $r('app.string.search') }).placeholderColor('#FF000000').placeholderFont({ size: 16, weight: 400 }).textAlign(TextAlign.Start).caretColor('#FF000000').width('100%').height(40).fontWeight(400).padding({ top: 9, bottom: 9 }).fontSize(16).backgroundColor(Color.White)Image($r('app.media.ic_public_search')).width(16).height(16).margin({ right: 20 })}.height(56).width('100%')}@Builder titleBar() {Text($r('app.string.tabBar1')).fontSize(24).fontWeight(500).fontColor('#18181A').textAlign(TextAlign.Start).height(56).width('100%')}build() {GridRow() {GridCol({ span: { xs: 12, lg: 8 } }) {this.titleBar()}GridCol({ span: { xs: 12, lg: 4 } }) {this.searchBar()}}.width('100%').height(this.currentBreakpoint === 'lg' ? 56 : 112).padding({ left: 12, right: 12 })}}

2、在sm和md断点下,标题栏和搜索栏占满12列,此时会自动换行显示。
3、在lg断点下,标题栏占8列而搜索栏占4列,此时标题栏和搜索栏在同一行中显示。

运营横幅

实现不同断点下的运营横幅:通过Swiper组件的displayCount属性,sm断点下显示一张图片,md断点下显示两张图片,lg断点下显示三张图片。

快捷入口

通过将justifyContent参数配置为FlexAlign.SpaceEvenly实现均分布局:在不同的断点下,快捷入口的5个图标始终均匀排布。

精品应用

通过List组件能力,实现延伸能力场景:随着可用显示区域的增加,精品应用中显示的图标数量也不断增加,[源码参考]。

/** Copyright (c) 2022-2023 Huawei Device Co., Ltd.* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/import { AppItem, MyAppSource } from '../model/HomeDataType'@Componentexport default struct IndexApps {private title: Resource@StorageProp('currentBreakpoint') currentBreakpoint: string = 'md'private apps: AppItem[] = []@BuilderappListHeader() {Row() {Text(this.title).width(100).fontSize(16).textAlign(TextAlign.Start).fontWeight(500)Blank()Text($r('app.string.more')).fontSize(14).textAlign(TextAlign.End).fontWeight(400).margin({ right: 2 })Image($r('app.media.ic_public_arrow_right')).width(12).height(18).opacity(0.9).objectFit(ImageFit.Fill)}.margin({ bottom: 9, top: 9 }).width('100%').alignItems(VerticalAlign.Bottom)}@BuilderappListItem(app:AppItem) {Column() {Image(app.image).width(this.currentBreakpoint === 'lg' ? 80 : 56).height(this.currentBreakpoint === 'lg' ? 80 : 56).margin({ bottom: 8 })Text(app.title).width(this.currentBreakpoint === 'lg' ? 80 : 56).height(16).fontSize(12).textAlign(TextAlign.Center).fontColor('#18181A').margin({ bottom: 8 })Text($r('app.string.install')).width(this.currentBreakpoint === 'lg' ? 80 : 56).height(28).fontColor('#0A59F7').textAlign(TextAlign.Center).borderRadius(this.currentBreakpoint === 'lg' ? 26 : 20).fontWeight(500).fontSize(12).padding({ top: 6, bottom: 6, left: 8, right: 8 }).backgroundColor('rgba(0,0,0,0.05)')}}build() {Column() {this.appListHeader()List({ space: this.currentBreakpoint === 'lg' ? 44 : 20}) {LazyForEach(new MyAppSource(this.apps), app => {ListItem() {this.appListItem(app)}}, app => app.id)}.width('100%').height(this.currentBreakpoint === 'lg' ? 140 : 120).listDirection(Axis.Horizontal)}.width('100%').height(this.currentBreakpoint === 'lg' ? 188 : 164).padding({ bottom: 8, left: 12, right: 12 })}}`HarmonyOS与OpenHarmony鸿蒙文档籽料:mau123789是v直接拿`

搜狗高速浏览器截图20240326151450.png

总体运行效果

通过将上述各页面在List() {}中引用组件后,可实现首页的组件整合渲染,即可完成整体页面开发。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/17809.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

蓝桥杯第1022题 玩具蛇 基础DFS C++ Java

题目 思路和解题方法 问题理解:此题要求找出将一条由16节正方形构成的玩具蛇放入4x4的方格中的不同方式数。每节蛇可以是直线或直角转弯,且蛇的形状需要完全覆盖盒子里的16个格子,每个格子仅被蛇的一个部分占据。 状态表示:使用一…

爷爷看了都会,打工人必备的摸鱼AI神器!免费!

去年,AI技术无疑成为了最为引人注目的焦点,层出不穷的创新应用令人目不暇接。尽管许多人对这股AI热潮的持久性持怀疑态度,但现实却用事实给予了最有力的反驳。AI所展现出的强大生产力,足以令人刮目相看。 而今年以来,…

springboot链接kafka异步发送消息

<dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka</artifactId></dependency> spring:kafka:bootstrap-servers:- ip:端口producer:retries: 0acks: 1batch-size: 16384properties:linger:ms: 100buff…

centos 记录用户登陆ip和执行命令

centos 记录用户登陆ip和执行命令 在/etc/profile 文件末尾添加如下代码&#xff1a; #!/bin/bash USER_IPwho -u am i 2>/dev/null | awk {print $NF} | sed -e s/[()]//g HISTDIR/usr/share/.history if [ -z "$USER_IP" ]; then USER_IPhostname fi…

VUE3学习第一篇:启动ruoyi

1、找到ruoyi的vue3版本 然后下载代码到本地&#xff0c; 我刚开始用的nodejs14报错&#xff0c; 后面换成nodejs16&#xff0c;启动前端成功了。 页面如下图所示

go panic

panic 能够改变程序的控制流&#xff0c;调用 panic 后会立刻停止执行当前函数的剩余代码&#xff0c;并在当前 goroutine 中递归执行调用方的 defer。 // A _panic holds information about an active panic. // // A _panic value must only ever live on the stack. // // …

【JPCS出版,EI稳定检索会议推荐】第四届计算机、遥感与航空航天国际学术会议(CRSA 2024)已成功申请JPCS出版,火热征稿中!

【EI核心、Scopus】第四届计算机、遥感与航空航天国际学术会议&#xff08;CRSA 2024&#xff09;将于2024年7月5-7日在日本大阪举行。计算机、遥感与航空航天国际学术会议为来自世界各地的研究学者、工程师、学会会员以及相关领域的专家们提供一个关于“计算机科学”、“遥感技…

体验SmartEDA的高效与便捷,电子设计从未如此简单

SmartEDA&#xff1a;革新电子设计&#xff0c;让高效与便捷触手可及 在快节奏的现代生活中&#xff0c;科技日新月异&#xff0c;各行各业都在寻求更高效、更便捷的解决方案。对于电子设计行业而言&#xff0c;SmartEDA的出现&#xff0c;无疑是一场革命性的变革。它以其高效…

【PG16】后 EL 7 时代,PG 16 如何在 CentOS 7 上运行

↑ 关注“少安事务所”公众号&#xff0c;欢迎⭐收藏&#xff0c;不错过精彩内容~ ★ 本文写于 2023-09-29 PostgreSQL 16 Released 9/14, PostgreSQL 16 正式发布。从发布公告^1 和 Release Notes^2 可以看到 PG16 包含了诸多新特性和增强改进。 性能提升&#xff0c;查询计划…

快速核对两个表格数据

快速核对两个表格数据的方法取决于数据的规模、复杂性以及你使用的工具。以下是一些常见的方法&#xff1a; 使用Excel或其他电子表格软件: VLOOKUP 或 HLOOKUP 函数&#xff1a;这些函数可以在一个表格中查找与另一个表格匹配的值&#xff0c;并返回对应的结果。条件格式&…

Genzai:一款针对物联网安全的多功能实用性工具套件

关于Genzai Genzai是一款针对物联网安全的多功能实用性工具套件&#xff0c;该工具旨在识别与物联网相关的仪表盘&#xff0c;并扫描它们以查找默认密码和安全问题&#xff0c;广大研究人员可以使用该工具来检测和提升物联网设备的安全性。 Genzai支持用户以输入的形式提供一个…

npm install安装时卡死时尝试切换npm镜像地址

当使用npm时&#xff0c;为了提高下载速度和稳定性&#xff0c;特别是针对国内的开发者&#xff0c;经常需要配置国内的镜像源&#xff0c;如淘宝npm镜像。以下是如何添加淘宝源等镜像内容的详细步骤和说明&#xff1a; 1. 淘宝npm镜像地址 淘宝npm镜像的地址在2022年6月30日…

简爱的思维导图怎么做?从这三个角度

简爱的思维导图怎么做&#xff1f;《简爱》作为夏洛蒂勃朗特的代表作&#xff0c;不仅是一部经典的爱情小说&#xff0c;也是探索女性独立与自我成长的文学巨著。为了深入理解这部作品&#xff0c;制作思维导图是一种高效的学习和分析工具。以下是三种不同的角度来创建《简爱》…

探讨开源与闭源大模型在AI领域的发展前景与挑战

一、引言 随着人工智能&#xff08;AI&#xff09;技术的飞速发展&#xff0c;大模型已成为推动AI技术进步的核心动力。在AI大模型的发展过程中&#xff0c;开源与闭源两种不同的发展路径各自展现出了独特的发展前景与挑战。本文将深入探讨这两种路径在AI领域的发展前景&#…

在马达驱动上的MOS产品选型分析与应用

电机的应用非常广泛&#xff0c;可以说大部分动的产品内部都有电机的身影&#xff0c;其主要的应用领域有风机、泵、散热风扇、电动工具、智能家居、以及汽车应用等等。随着各国出台了更加严格的用电标准&#xff0c;节能电机成为了市场关注的热点&#xff0c;而BLDC电机具有高…

K8S集群中Yaml文件详解

目录 一、Yaml概述 二、Yaml基本语法 三、Yaml数据结构 四、K8S资源清单描述方法 五、api资源版本标签 六、Yaml文件示例详解 1.deployment.yaml文件详解 2.Pod yaml文件详解 3.Service yaml文件详解 七、Yaml文件相关操作 1.试运行 2.生成yaml格式 3.生成json格式…

手搓顺序表(C语言)

目录 SeqList.h SeqList.c 头插尾插复用任意位置插入 头删尾删复用任意位置删除 SLtest.c 测试示例 顺序表优劣分析 SeqList.h //SeqList.h#pragma once#include <stdio.h> #include <assert.h> #include <stdlib.h> #define IN_CY 3typedef int S…

深入分析C#中的“编写器”概念——代码修改、注解与重构

文章目录 1. 编写器&#xff08;Writer&#xff09;的概念2. 编写器的作用和工作原理3. 编写器的重要性4. 写入器常用方法5. 写入器示例6. 编写器示例——使用Fody进行代码注解和重构7. 总结 在软件开发过程中&#xff0c;代码的维护和更新是至关重要的。C#作为一种流行的编程语…

单词学习——不断更新

suppress: sup - press 抑制&#xff0c;镇压 subtle: sub - tle 微妙的 suspend: sus - pend 延缓&#xff0c;悬挂 supplement: sup - ple - ment: 补充 suspicious: sus - pi - cious 可疑的 depress: de -press 压抑 emit: e - mit 发出 entail: en - tail 涉及 fo…

3.00001 postgres如何初始化系统参数?

文章目录 加载参数整体流程参数结构举例&#xff1a;ConfigureNamesBool 初始化参数 InitializeGUCOptionsbuild_guc_variablesInitializeOneGUCOptionInitializeGUCOptionsFromEnvironment 命令行添加SelectConfigFiles配置 加载参数整体流程 我们先看下guc参数是如何管理的。…