我的导入:
implementation "com.airbnb.android:lottie:3.2.2"在我的splash_layout中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash"/>
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animation_view"
android:layout_width="100dp"
android:layout_height="100dp"
app:lottie_fileName="logo_android.json"
app:lottie_loop="true"
app:lottie_autoPlay="true"
app:lottie_imageAssetsFolder="demo"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>在SplashActivity中:
private LottieAnimationView animationView;
(...)
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_layout);
animationView=findViewById(R.id.animation_view);
animationView.playAnimation();
(...)
}我的图像文件夹在src/main/res/assets/demo中。logo_android.json文件位于src/main/assets
这样,动画根本不会显示。没有显示任何一张图像。怎样才能让动画工作起来?
如果重要的话,JSON文件看起来像这样:
{"v":"5.5.8","fr":25,"ip":0,"op":400,"w":800,"h":400,"nm":"logo_android","ddd":0,"assets":[{"id":"image_0","w":396,"h":51,"u":"images/","p":"img_0.png","e":0},{"id":"image_1","w":122,"h":215,"u":"images/","p":"img_1.png","e":0},(...)发布于 2019-11-21 17:20:07
解决了它。
如果它可以帮助某人,您必须将图像放在src/main/assets/images中
发布于 2020-11-09 05:26:07
通过以下方式让它正常工作:
if(lottieTest.getFrame() == lottieTest.getMaxFrame()) {
lottieTest.setFrame(1);
}请参考this。
https://stackoverflow.com/questions/58953963
复制相似问题