当前位置: 首页 > news >正文

【鸿蒙HarmonyOS】鸿蒙app开发入门到实战教程(三):实现一个音乐列表的页面

鸿蒙里面,实现一个音乐播放的列表,模拟数组的数据展示

实现效果

在这里插入图片描述

代码实现

  • 准备数据
songs:SongItemTypes[] = [{img:'https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/0.jpg',name:'直到世界的尽头',author:'WANDS'},{img:'https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/1.jpg',name:'画',author:'赵磊'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/2.jpg',name:'Sweet Dreams',author:'TPaul sax / Eurythmics'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/3.jpg',name:'奢香夫人',author:'凤凰传奇'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/4.jpg',name:'空心',author:'光泽'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/5.jpg',name:'反转地球',author:'潘玮柏'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/6.jpg',name:'No.9',author:'T-ara'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/7.jpg',name:'孤独',author:'G.E.M.邓紫棋'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/8.jpg',name:'Lose Control',author:'Hedley'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/9.jpg',name:'倩女幽魂',author:'张国荣'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/10.jpg',name:'反转地球',author:'潘玮柏'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/11.jpg',name:'苦笑',author:'汪苏泷'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/12.jpg',name:'一生所爱',author:'卢冠廷 / 莫文蔚'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/13.jpg',name:'月半小夜曲',author:'李克勤'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/14.jpg',name:'Rolling in the peep',author:'Adele'},{img:'http://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/HeimaCloudMusic/1.jpg',name:'Beyond',author:'海阔天空'}]
  • 标题的实现
Text("猜你喜欢").fontColor('#fff').width('100%').margin({bottom:10})
  • 列表的实现
List(){ForEach(this.songs,(item:SongItemTypes,index:number) => {ListItem(){Row(){Stack(){Image(item.img).width(80).border({radius:8}).margin({right:10})if(this.currentIndex == index){Image($r('app.media.wave')).width(40)}}.alignContent(Alignment.Bottom)Column(){Text(item.name).fontColor(Color.White).width('100%')Row(){Text("Vip").fontColor(Color.White).padding({top:2,right:5,bottom:2,left:5}).fontColor(Color.Grey).margin({right:10}).border({width:1,radius:8,color:Color.Grey})Text(item.author).fontColor(Color.White).fontColor(Color.Grey)}.width('100%').margin({top:20})}.layoutWeight(1)Image($r('app.media.more')).width(24).fillColor('#fff')}.width('100%').height(80).onClick(() => {this.currentIndex = index})}.margin({bottom:10})
})
}.scrollBar(BarState.Off)
  • 点击当前项的时候,出现音量闪烁的图片
if(this.currentIndex == index){Image($r('app.media.wave')).width(40)
}

完整代码

import {SongItemTypes} from '../types'@Entry
@Component
struct  FourthPage {@State currentIndex:number = -1build() {Column(){Text("猜你喜欢").fontColor('#fff').width('100%').margin({bottom:10})List(){ForEach(this.songs,(item:SongItemTypes,index:number) => {ListItem(){Row(){Stack(){Image(item.img).width(80).border({radius:8}).margin({right:10})if(this.currentIndex == index){Image($r('app.media.wave')).width(40)}}.alignContent(Alignment.Bottom)Column(){Text(item.name).fontColor(Color.White).width('100%')Row(){Text("Vip").fontColor(Color.White).padding({top:2,right:5,bottom:2,left:5}).fontColor(Color.Grey).margin({right:10}).border({width:1,radius:8,color:Color.Grey})Text(item.author).fontColor(Color.White).fontColor(Color.Grey)}.width('100%').margin({top:20})}.layoutWeight(1)Image($r('app.media.more')).width(24).fillColor('#fff')}.width('100%').height(80).onClick(() => {this.currentIndex = index})}.margin({bottom:10})})}.scrollBar(BarState.Off)}.backgroundColor("#000").width('100%').height('100%').padding({left:10,right:10}).expandSafeArea([SafeAreaType.SYSTEM],[SafeAreaEdge.TOP,SafeAreaEdge.BOTTOM])}
}

在这里插入图片描述
这样就实现了一个模拟的音乐列表页面


文章转载自:
http://asyndetic.sxnf.com.cn
http://avirulence.sxnf.com.cn
http://aortic.sxnf.com.cn
http://chitinous.sxnf.com.cn
http://antalgic.sxnf.com.cn
http://adaptability.sxnf.com.cn
http://approximately.sxnf.com.cn
http://canescent.sxnf.com.cn
http://acrosin.sxnf.com.cn
http://caramel.sxnf.com.cn
http://anthodium.sxnf.com.cn
http://assaulter.sxnf.com.cn
http://balmusette.sxnf.com.cn
http://assignation.sxnf.com.cn
http://agroindustrial.sxnf.com.cn
http://certosina.sxnf.com.cn
http://carbine.sxnf.com.cn
http://admissibility.sxnf.com.cn
http://chevrette.sxnf.com.cn
http://berkeleyism.sxnf.com.cn
http://augusta.sxnf.com.cn
http://backstab.sxnf.com.cn
http://bastardly.sxnf.com.cn
http://acock.sxnf.com.cn
http://archery.sxnf.com.cn
http://antisocial.sxnf.com.cn
http://candied.sxnf.com.cn
http://annullable.sxnf.com.cn
http://aggregation.sxnf.com.cn
http://bsn.sxnf.com.cn
http://www.dtcms.com/a/281153.html

相关文章:

  • Flutter Socket 连接方案分析与适用场景
  • RestTemplate 实现后端 HTTP 调用详解
  • spring-ai-alibaba 多模态之音频
  • 前端Vue.js面试题(4)
  • 超详细 anji-captcha滑块验证springboot+uniapp微信小程序前后端组合
  • 如何定义一个只能在堆上或栈上生成对象的类
  • Python初学者笔记第十二期 -- (集合与字典编程练习题)
  • U-Boot 中增加 GIC-400中断服务程序
  • Copula理论:覆盖相关性分析、极值相依性、回归建模、时间序列预测、贝叶斯网络,R/Python双语言实现+AI编程辅助(科研绘图与结果呈现)
  • Nestjs框架: 数据库多租户模式与动态模块初探
  • Oracle日期时间函数说明及与MySql区别说明
  • 同济医院R语言训练营第三期开讲!上交大张维拓老师主讲
  • RabbitMQ工作流程
  • SQL学习记录01
  • 15.图像 模板轮廓检测
  • 李白周游记50篇
  • linux-develop
  • 基于Alpine构建MySQL镜像
  • 第二阶段-第二章—8天Python从入门到精通【itheima】-129节(MySQL的安装)
  • 【前后端】Node.js 模块大全
  • 巨坑检查无误还报错is not mapped MappingException: Unknown entity:@Entity
  • DeepSWE:通过强化学习扩展训练开源编码智能体
  • 多层 `while` 循环中,`break` 的行为
  • ES2023 新特性解析_数组与对象的现代化操作指南
  • 二分查找栈堆
  • 【C语言进阶】字符函数和字符串函数的内部原理
  • “ModuleNotFoundError“深度解析:Python模块导入问题的终极指南
  • PHP语言基础知识(超详细)第二节
  • OSPFv3中LSA参数
  • dbever 导出数据库表的建表语句和数据插入语句