简体   繁体   English

在lottie中加载动画的kotlin android问题

[英]kotlin android problem on animation loading in lottie

i want load animation from json file ... and json file is in assets .. i'm facing this problem我想从json文件加载动画......并且json文件在资产中......我面临这个问题

binding.animationView.setAnimation(assets.open("failanimation.json"))

compiler showing red line on setAnimation编译器在setAnimation上显示红线

.json 文件它应该在 app/src/main/assets/ 文件夹下,不需要asset.open只需在你的情况下放置setAnimation(json_filename)它应该是setAnimation("failanimation.json")

Try this once-试试这个 -

Step 1 -Add your Lottie animation file in raw resource folder app第 1 步 - 在原始资源文件夹应用程序中添加您的 Lottie 动画文件

res > right-click > New > Folder > Raw Resource Folder res > 右键单击​​ > 新建 > 文件夹 > 原始资源文件夹

Step 2- XML code第 2 步 - XML 代码

<com.airbnb.lottie.LottieAnimationView
        android:id="@+id/animationView"
        android:layout_width="100dp"
        android:layout_height="100dp"
        app:lottie_autoPlay="true"
        app:lottie_loop="true"  />

Step 3 -第 3 步 -

binding.animationView.setAnimation(R.raw.failanimation)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM