【发布时间】:2019-11-20 12:05:32
【问题描述】:
我的导入:
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},(...)
【问题讨论】:
-
如果你已经在xml中指定了,你就不需要从代码中调用它。
-
我在代码中没有它,但由于它不起作用,我将它添加到代码中尝试,但也没有用...
-
不会是您的 json 文件中的问题吗?请尝试使用 LottieFiles.com 的一些内容
-
乐天动画网站上正在播放动画吗?如果是,请尝试包装内容的高度和宽度
-
已经尝试过包装内容