
这次的实战案例难度较大知识点概述的十分的全面,其中还包括了一些新的知识点比如(主体页面内容的滚动-Scroll组件),案例中所用的图标来自于阿里云的图标库。代码量也是达到了300行,所用组件众多,大都是嵌套应用。 阿里云图标库
croll组件是鸿蒙开发中的一种可滚动的容器组件,用于处理内容显示超出屏幕或指定区域的情况。
鸿蒙(HarmonyOS)是一个多智能终端的操作系统,由华为开发。作为鸿蒙开发的一部分,Scroll组件在用户界面构建中扮演了关键角色,特别是在应用程序需要展示过多信息而无法在一屏内完全显示时。Scroll组件通过允许内容滚动,增强了应用的用户体验和界面的动态交互能力。
在 HarmonyOS 的 XML 布局文件中,您可以使用 <Scroll> 标签来定义一个可滚动的区域。
通常情况下,会在 <Scroll> 内部放置一个 <Column> 或 <Row> 组件,这样可以更方便地组织内部的内容。
<Scroll> 内部放置了大量组件,可能会导致性能问题。在这种情况下,考虑使用虚拟列表(如 List 组件),它可以只渲染当前可见的部分,从而提高性能。
层叠布局是鸿蒙开发中用于在屏幕上预留一块区域来显示组件中的元素,提供元素可以重叠的布局方式。
鸿蒙(HarmonyOS)是一个面向多智能终端的操作系统,由华为开发。在鸿蒙应用开发过程中,层叠布局是一种重要的用户界面布局方式,它通过Stack容器组件实现位置的固定定位与层叠,使得容器中的子元素依次入栈,后一个子元素覆盖前一个子元素。这种布局方式不仅增强了页面的视觉效果,还能实现更加复杂的交互设计。以下将具体分析层叠布局的具体特性和应用场景:

@Entry
@Component
struct Index {
build() {
// 1.整体Stack布局+底部的tab
// 2.主体区域的架子:头部+主题页面(主题页面可滚动)
Stack({alignContent:Alignment.Bottom}){
// 1.1主题展示区
Stack({alignContent:Alignment.Top}){
// 头部
Row(){
// 左边
Row(){
Text('开封').fontColor('#fff')
Image($r('app.media.zfb_public_arrow_down_0'))
.width(20)
.fillColor('#fff')
}
// 中间
Row(){
Image($r('app.media.zfb_public_search'))
.width(20)
.fillColor('#666')
.margin({left:5,right:5})
Text('证件中心,查看电子...')
.layoutWeight(1)
.textOverflow({
overflow:TextOverflow.Ellipsis// 设置文字溢出效果
})
// 必须配合maxLines才有效果
.maxLines(1)// 设置显示的行数
Text('搜索')
.width(55)
.fontColor('#5b73de')
.fontWeight(700)
.textAlign(TextAlign.Center)
.border({
width:{left:1},
color:'#ccc'
})
}
.height(32)
.layoutWeight(1)
.backgroundColor('#fff')
.borderRadius(5)
.margin({left:12,right:12})
// 右边
Image($r('app.media.zfb_public_add_norm'))
.width(30)
.fillColor('#fff')
}
.padding({left:10,right:10})
.width('100%')
.height(60)
.backgroundColor('#5b73de')
.zIndex(10)// 头部层级最高
// 主体页面
// Column / Row不具备滚动效果
Scroll(){
Column(){
// top快捷按钮区域
Row(){
// 扫一扫
Column(){
Image($r('app.media.zfb_public_scan'))
.width(36)
.fillColor('#fff')
Text('扫一扫')
.fontColor('#fff')
}
.layoutWeight(1)
// 设置
Column(){
Image($r('app.media.zfb_public_settings'))
.width(36)
.fillColor('#fff')
Text('设置')
.fontColor('#fff')
}
.layoutWeight(1)
// 导航
Column(){
Image($r('app.media.zfb_public_navigation'))
.width(36)
.fillColor('#fff')
Text('导航')
.fontColor('#fff')
}
.layoutWeight(1)
// 卡包
Column(){
Image($r('app.media.zfb_desktop_servicewidgets'))
.width(36)
.fillColor('#fff')
Text('卡包')
.fontColor('#fff')
}
.layoutWeight(1)
}
.backgroundColor('#5b73de')
.padding({top:5,bottom:15})
// 主体区域
Column(){
// 导航区
Column({space:10}){
Row(){
Column(){
Image($r('app.media.zfb_01'))
.width(28).margin({bottom:8})
Text('市民中心')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
Column(){
Image($r('app.media.zfb_02'))
.width(28).margin({bottom:8})
Text('手机充值')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
Column(){
Image($r('app.media.zfb_03'))
.width(28).margin({bottom:8})
Text('滴滴出行')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
Column(){
Image($r('app.media.zfb_04'))
.width(28).margin({bottom:8})
Text('火车票机票')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
Column(){
Image($r('app.media.zfb_05'))
.width(28).margin({bottom:8})
Text('生活缴费')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
}
Row(){
Column(){
Image($r('app.media.zfb_06'))
.width(28).margin({bottom:8})
Text('芭芭农场')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
Column(){
Image($r('app.media.zfb_07'))
.width(28).margin({bottom:8})
Text('花呗')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
Column(){
Image($r('app.media.zfb_08'))
.width(28).margin({bottom:8})
Text('蚂蚁保')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
Column(){
Image($r('app.media.zfb_09'))
.width(28).margin({bottom:8})
Text('蚂蚁森林')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
Column(){
Image($r('app.media.zfb_10'))
.width(28).margin({bottom:8})
Text('饿了么')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
}
Row(){
Column(){
Image($r('app.media.zfb_11'))
.width(28).margin({bottom:8})
Text('转账')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
Column(){
Image($r('app.media.zfb_12'))
.width(28).margin({bottom:8})
Text('余额宝')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
Column(){
Image($r('app.media.zfb_13'))
.width(28).margin({bottom:8})
Text('信用卡还款')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
Column(){
Image($r('app.media.zfb_14'))
.width(28).margin({bottom:8})
Text('芝麻信用')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
Column(){
Image($r('app.media.zfb_15'))
.width(28).margin({bottom:8})
Text('更多')
.fontSize(12).fontColor('#666')
}
.layoutWeight(1)
}
}
.padding(10)
// 产品区
Column(){
Image($r('app.media.zfb_pro01'))
.width('100%')
Image($r('app.media.zfb_pro02'))
.width('100%')
Image($r('app.media.zfb_pro03'))
.width('100%')
Image($r('app.media.zfb_pro04'))
.width('100%')
Image($r('app.media.zfb_pro05'))
.width('100%')
Image($r('app.media.zfb_pro06'))
.width('100%')
Image($r('app.media.zfb_pro07'))
.width('100%')
}
}
.width('100%')
.backgroundColor('#f6f6f6')
.borderRadius({
topLeft:20,
topRight:20
})
}
.width('100%')
.padding({top:60,bottom:60})
}
}
.width('100%')
.height('100%')
// 1.2底部tab导航区
Row(){
// 支付宝logo
Column(){
Image($r('app.media.zfb_logo'))
.width(35)
}
.layoutWeight(1)
// 回家
Column(){
Image($r('app.media.zfb_public_home'))
.width(28).margin({bottom:2})
Text('回家')
.fontSize(12)
}
.layoutWeight(1)
// 视频
Column(){
Image($r('app.media.zfb_gallery_album_damage_video'))
.width(28).margin({bottom:2})
Text('视频')
.fontSize(12)
}
.layoutWeight(1)
// 消息
Column(){
Image($r('app.media.zfb_public_comments'))
.width(28).margin({bottom:2})
Text('消息')
.fontSize(12)
}
.layoutWeight(1)
// 我的
Column(){
Image($r('app.media.zfb_public_contacts'))
.width(28).margin({bottom:2})
Text('我的')
.fontSize(12)
}
.layoutWeight(1)
}
.width('100%')
.height(60)
.backgroundColor('#fbfcfe')
}
.width('100%')
.height('100%')
.backgroundColor('#5b73de')
}
}