[英]How to check if lottie animation works?
Im trying to do a simple loading with lottie.我试图用lottie 做一个简单的加载。 I found this animation: https://lottiefiles.com/18563-cooking# =我发现这个 animation: https://lottiefiles.com/18563-cooking# =
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animation_view"
android:layout_width="200dp"
android:layout_height="200dp"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/test"
/>
It's stored in SRC/Main/res/raw but I get this error:它存储在 SRC/Main/res/raw 但我收到此错误:
You must set an images folder before loading an image. Set it with LottieComposition#setImagesFolder or LottieDrawable#setImagesFolder
I try to add to assets folder with app:lottie_fileName
我尝试使用app:lottie_fileName
添加到资产文件夹
So I think the animation is bug, because of this I want to know if exist some tools or command to know if animation works.所以我认为 animation 是错误,因此我想知道是否存在一些工具或命令来了解 animation 是否有效。
in my case,my lottie json file contains code fragment like this:就我而言,我的乐天 json 文件包含如下代码片段:
{
"id": "image_0",
"w": 1241,
"h": 802,
"u": "images/",
"p": "image_01.png",
"e": 0
}
it means it need image image_01.png
to work.这意味着它需要图像image_01.png
才能工作。 and it will look for it from folder images/
.它将从文件夹images/
中查找它。
if you don't provide this images folder location it will throw this exception.如果您不提供此图像文件夹位置,它将引发此异常。
here is the step i solved my problem.这是我解决问题的步骤。
assets
folder, the folder sturcture:将文件夹 images 添加到assets
文件夹中,文件夹结构:+-assets +----images ---------image_01.png
app:lottie_imageAssetsFolder="images"
in the xml( or添加app:lottie_imageAssetsFolder="images"
在 xml( 或you can add setImageAssetsFolder("/images");
你可以添加setImageAssetsFolder("/images");
in code.在代码中。 ) )
Save the.json file in /assets directory.将 .json 文件保存在 /assets 目录中。 Use below code:使用以下代码:
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/iv_cooking_anim"
android:layout_width="200dp"
android:layout_height="200dp"
app:lottie_autoPlay="true"
app:lottie_loop="false"
app:lottie_enableMergePathsForKitKatAndAbove="true"
app:lottie_fileName="cooking_anim.json"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.