HarmonyOS Image里面可以插入json动画文件么

HarmonyOS
2024-12-25 13:56:40
556浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

可以使用lottie加载网络Json,参考链接:https://gitee.com/openharmony-tpc/lottieArkTS

参考链接代码加载网络json部分,核心demo:

Row({ space: 10 }) {
  // 关联画布
  Canvas(this.canvasRenderingContext)
    .width(200)
    .height(200)
    .backgroundColor(Color.Gray)
    .onReady(() => {
      // 可在此生命回调周期中加载动画,可以保证动画尺寸正确
      this.animateItem?.resize();

      lottie.destroy(this.animateName)
      this.animateItem = lottie.loadAnimation({
        uri: "xxx",
        isNetwork: false,
        container: this.canvasRenderingContext,
        renderer: 'canvas', // canvas 渲染模式
        loop: true,
        autoplay: true,
        name: this.animateName,
      })
      this.animateItem.addEventListener('error', (args: Object): void => {
        console.info("error:" + JSON.stringify(args));
      });

    })
    .onClick(() => {
      lottie.destroy(this.animateName)
      this.animateItem = lottie.loadAnimation({
        uri: "xxx",
        isNetwork: false,
        container: this.canvasRenderingContext,
        renderer: 'canvas', // canvas 渲染模式
        loop: true,
        autoplay: true,
        name: this.animateName,
      })
      this.animateItem.addEventListener('error', (args: Object): void => {
        console.info("error:" + JSON.stringify(args));
      });
    })
    .onDisAppear(() => {
      lottie.destroy(this.animateName);
    })
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
分享
微博
QQ
微信
回复
2024-12-25 16:24:35


相关问题
Image图片加载缓慢,有什么方案
2270浏览 • 1回复 待解决
鸿蒙里面有alpha动画
7486浏览 • 1回复 已解决
TabList可以添加图片
8439浏览 • 3回复 待解决
HarmonyOS @state可以修饰对象数组
667浏览 • 1回复 待解决
HarmonyOS 如何读取本地json文件
1060浏览 • 1回复 待解决