我所做的:
步骤1)
在 gradle 中添加了以下依赖项:
compile 'com.airbnb.android:lottie:2.0.0-beta4'
步骤2)
Airbnb没有告诉我们在哪里放置动画JSON文件。但是,我在他们的示例应用程序中看到它放在app/src/main/assets。所以我创建了那个文件夹并在里面插入了一些JSON动画。
步骤3)
在activity_main.xml中添加以下内容:
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animation_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:lottie_fileName="EmptyState.json"
app:lottie_loop="true"
app:lottie_autoPlay="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
运行应用程序时,我遇到了以下错误:
04-29 12:55:37.253 21877-21877/com.example.ross.testitout E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ross.testitout, PID: 21877
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ross.testitout/com.example.ross.testitout.MainActivity}: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class com.airbnb.lottie.LottieAnimationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
我想知道自己做错了什么。同时,缺乏深入的教程,这让我很遗憾,像我这样的初学者需要花费比必要更长的时间来弄清楚事情。