鸿蒙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文件路径
          })
        })
    }
  }

}
相关推荐
桑榆4167 小时前
JSON 格式
json
小当家.10511 小时前
LLM结构化输出与流式响应:从JSON修复到SSE全链路
llm·json
前网易架构师-高司机1 天前
带标注的羽毛球运动员,裁判,羽毛球识别数据集,识别率84.4%,2879张图,支持yolo,coco json,voc xml,文末有模型训练代码
xml·yolo·json·数据集·羽毛球·裁判
leisoo80971 天前
股票数据本地化存储实战:JSON、数据库与列式存储的方案对比
jvm·数据库·json
切糕师学AI1 天前
从压缩到查询:PostgreSQL中JSON数据的存储与处理实践
数据库·postgresql·json
doubt。1 天前
大模型prompt工程Zero-Shot与Few-Shot以及json格式
人工智能·深度学习·机器学习·语言模型·json·prompt
烟锁池塘柳02 天前
Conda 创建环境报错:Unable to read repodata JSON file,清华源 pkgs/free 失效解决方法
json·conda
云水一下3 天前
零基础玩转bWAPP靶场(四十五):XSS - Reflected (JSON)
web安全·json·xss·bwapp·reflected
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ4 天前
Spring‑AI Document 对象 JSON 字段详解
人工智能·spring·json
sunywz4 天前
【从零搭建物联网智能充电桩系统】2、自定义二进制协议:设备为什么不用 JSON?
python·物联网·json