鸿蒙app开发中 拿到json文件数据进行动画的播放

1.效果 类似于这样的 播放动画

2.实现步骤 使用lottie 组件。将 json 文件按照官方文档的步骤进行 放入 就能进行播放了

官网的地址

详细的代码。直接封装成一个组件 ----- 按照组件使用的方式就行

javascript 复制代码
// 播放的动画
@Component
export struct radioPlayAnimation{
  // 构建上下文
  private renderingSettings: RenderingContextSettings = new RenderingContextSettings(true)
  private canvasRenderingContext: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.renderingSettings)
  private animateItem: AnimationItem | null = null;


  build() {
    Row(){
      Canvas(this.canvasRenderingContext)
        .width(14)
        .height(14)
        .onReady(() => {
          this.animateItem = lottie.loadAnimation({
            container: this.canvasRenderingContext, // 绑定画布
            renderer: 'canvas',
            loop: true, // 循环播放
            autoplay: true, // 自动播放
            // name: this.animateName,
            path: 'common/radio_play.json' // JSON文件路径
          })
        })
    }
  }

}
相关推荐
鲸渔20 小时前
【AI Agent系列课程13-Python 基础13】JSON 读写:结构化数据交换基础
开发语言·python·json·ai编程
aiotto资源分享4 天前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
一起学安全技术5 天前
拆大模型 10|结构化输出:让模型返回数据,而不是一段话
人工智能·语言模型·json
用户298698530145 天前
在 Python 中把 Word 文档转换为 JSON 的三种实现方式
python·json·api
FRing037 天前
vue2干货总结10(json-server、vant-ui、postcss插件、axios二次封装、图形验证码、toast轻提示)
开发语言·前端·vue.js·ui·json·vue2·postcss
用户298698530147 天前
使用 Python 将 JSON 转换为 Word 文档的实践指南
python·json·api
九英里路7 天前
protobuf快速上手
网络·c++·中间件·json·谷歌·序列化·protobuf
wuyk5558 天前
Spider-第09讲-三格式落盘CSV-Excel-JSON
爬虫·python·json·excel
wuyk5559 天前
Spider-第07讲-JSON接口与正则提取
爬虫·python·json
xbzb11 天前
镜像到底存在哪:/var/lib/docker 的四级映射与 daemon.json 配置
docker·容器·json·镜像·daemon.json·四级