Lottie 动画全闪屏不全屏

use*_*075 7 android android-animation android-layout lottie

我必须在 Android 中使用 Lottie 动画作为闪屏。我使用了匹配父级的宽度和高度。但它向我展示了屏幕边缘的一些填充,如附图所示。如果我使用scaletype作为fitXY,那么它的图像会在某些设备上拉伸。我如何为所有设备分辨率使用lottie动画文件,或者我是否需要要求我们的设计师更改文件?

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/retention_bg_welcome_color">

<com.airbnb.lottie.LottieAnimationView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:lottie_autoPlay="true"
    app:lottie_fileName="test_lottie.json"
    android:adjustViewBounds="true"
    app:lottie_loop="true"
    app:lottie_speed="0.8" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Car*_*ten 13

android:scaleType="centerCrop"为我解决了这个问题:

完整的 XML:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/home_splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:gravity="center_horizontal">

<com.airbnb.lottie.LottieAnimationView
    android:id="@+id/animation_view"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:duplicateParentState="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:lottie_autoPlay="true"
    app:lottie_fileName="test.json"
    app:lottie_loop="false"
    android:scaleType="centerCrop"
    tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)


小智 -1

在您的活动中使用它

requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
Run Code Online (Sandbox Code Playgroud)

  • 感谢您的答复。但这对我不起作用。 (2认同)