写点什么

鸿蒙开发:ArkUI 实现语音笔记应用布局

作者:chengxujianke
  • 2025-05-22
    广东
  • 本文字数:1033 字

    阅读完需:约 3 分钟

最近在尝试用 HarmonyOS NEXT 的 ArkUI 方舟开发框架开发一款商务办公类语音笔记应用,记录一下开发过程中的一些实践心得。ArkUI 方舟开发框架的声明式 UI 设计确实让界面开发效率提升不少。在构建语音笔记应用时,通过简洁的 ArkTS 语法就能实现复杂的界面交互。下面分享一个实现语音录制列表界面的代码片段,基于 HarmonyOS NEXT API12 版本:typescript


// 语音笔记列表项组件 @Componentstruct VoiceNoteItem {@Prop noteTitle: string@Prop recordTime: string@Prop duration: string


build() {Column() {Row() {Image($r('app.media.ic_voice_note')).width(24).height(24).margin({ right: 12 })


    Column() {      Text(this.noteTitle)        .fontSize(16)        .fontWeight(FontWeight.Medium)      Text(this.recordTime)        .fontSize(12)        .opacity(0.6)    }    .layoutWeight(1)        Text(this.duration)      .fontSize(14)  }  .padding(12)  .width('100%')    Divider()    .strokeWidth(0.5)    .color('#f0f0f0')}
复制代码


}}


// 主页面 @Entry@Componentstruct VoiceNoteList {@State notes: Array<{title: stringtime: stringduration: string}> = [{ title: '项目会议记录', time: '2024-03-15 14:30', duration: '12:34' },{ title: '产品需求讨论', time: '2024-03-14 10:15', duration: '08:21' }]


build() {Column() {// 标题栏 Row() {Text('语音笔记').fontSize(20).fontWeight(FontWeight.Bold)


    Button('新建')      .type(ButtonType.Capsule)      .onClick(() => {        // 跳转到录音界面      })  }  .justifyContent(FlexAlign.SpaceBetween)  .padding(16)    // 笔记列表  List({ space: 8 }) {    ForEach(this.notes, (item) => {      ListItem() {        VoiceNoteItem({          noteTitle: item.title,          recordTime: item.time,          duration: item.duration        })      }    })  }  .layoutWeight(1)  .width('100%')}.height('100%')
复制代码


}}


在 HarmonyOS NEXT 上使用 ArkUI 开发时,发现其响应式设计能很好地适配不同尺寸的设备,这对商务办公场景下的多设备协同很有帮助。组件化的开发方式也让代码结构更清晰,便于后期维护。目前还在学习 ArkUI 更高级的特性,比如状态管理和动画效果,希望能进一步提升应用的用户体验。HarmonyOS NEXT 的分布式能力也是下一步要探索的重点,考虑如何让语音笔记在不同设备间无缝流转。

用户头像

chengxujianke

关注

还未添加个人签名 2025-03-07 加入

还未添加个人简介

评论

发布
暂无评论
鸿蒙开发:ArkUI实现语音笔记应用布局_chengxujianke_InfoQ写作社区