0
点赞
收藏
分享

微信扫一扫

Android中Lottie加载本地资源动画字体和设置文本和图片

单调先生 2022-03-12 阅读 184

文章目录

1.初始化本地zip文件

LottieCompositionFactory.fromZipStream(
                ZipInputStream(FileInputStream("/storage/emulated/0/Android/data/packageName/files/test.zip")),
                "test"
            )
                .addListener {
                     testLottieAnimationView.setComposition(it)
                     testLottieAnimationView.playAnimation()
                }

2.加载本地字体资源

        testLottieAnimationView.setFontAssetDelegate(object : FontAssetDelegate() {
            override fun fetchFont(fontFamily: String?): Typeface {
                return Typeface.createFromFile("/storage/emulated/0/Android/data/packageName/files/Hei.ttf")
            }

            override fun getFontPath(fontFamily: String?): String {
                return "/storage/emulated/0/Android/data/packageName/files/Hei.ttf"
            }
        })

3.设置Lottie动画中的文本 替换对应的key

这个key是设计那边指定好的 具体是什么可以问一下

  val  textDelegate = TextDelegate(testLottieAnimationView)
  textDelegate.setText("key", "要设置的文本")
  

4.设置Lottie动画中图片

testLottieAnimationView.updateBitmap( "key", bitmap)

其中bitmap可以自己转

举报

相关推荐

0 条评论