原生 Android 启动画面中的 Lottie 动画

Mer*_*aju 6 android splash-screen kotlin lottie-android lottie

是否可以在启动画面的布局中加载 Lottie 动画?

目前我的启动画面布局是这样的:

背景文件

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">

<item android:drawable="@drawable/path_background_gradient" />

<item
    android:drawable="@drawable/ic_locky"
    android:gravity="center" />

</layer-list>
Run Code Online (Sandbox Code Playgroud)

样式文件

<!-- Splash Launcher UI theme. -->
<style name="Locky.Theme.Launcher" parent="Locky.Theme">
    <item name="android:windowBackground">@drawable/custom_background_launcher</item>
    <item name="colorPrimary">@color/background_gradient_accent_start</item>
    <item name="colorPrimaryDark">@color/background_gradient_accent_start</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我用它来防止 android 冷启动时出现白屏。

但是ic_locky我想使用 Lottie 动画而不是图标。有可能这样做吗?因为有许多应用程序在启动画面中使用动画徽标。

请帮我。

谢谢你们。

Oll*_*erg 0

由于对 WindowManager 的控制很少,您可以在 windowbackground 中使用动画的静态图像,然后将其替换为 lotie 动画。

洛蒂:

implementation 'com.airbnb.android:lottie:$lottieVersion'
Run Code Online (Sandbox Code Playgroud)

目前最高版本好像是3.4.0。

然后使用 LottieAnimationView 加载动画:

<com.airbnb.lottie.LottieAnimationView
    android:id="@+id/lav_thumbUp"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_marginStart="80dp"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:lottie_autoPlay="false"
    app:lottie_fileName="thumb_up.json"
    app:lottie_loop="false"
    app:lottie_speed="1.25" />
Run Code Online (Sandbox Code Playgroud)

了解更多:https ://github.com/airbnb/lottie-android/blob/master/README.md

  • 嘿,我在静态加载后使用了 Lottie 动画,但我注意到的是 - “白屏闪烁几毫秒,然后动画开始”。有什么解决办法吗? (2认同)