全屏启动的Lottie动画无法全屏显示

时间:2020-09-06 05:27:12

标签: android android-layout android-animation lottie lottie-android

我必须在Android的启动画面中使用抽奖动画。我已经使用match parent作为宽度和高度。但是它向我展示了在屏幕边缘的一些填充,如上图所示。如果我将scaletype用作fitXY,则在某些设备上会拉伸图像。如何在所有设备分辨率下使用抽奖动画文件,还是需要询问设计人员文件的更改?

<?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>

enter image description here

4 个答案:

答案 0 :(得分:0)

在您的活动中使用它

requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

答案 1 :(得分:0)

  /**
   * Disable the extraScale mode in {@link #draw(Canvas)} function when scaleType is FitXY. It doesn't affect the rendering with other scaleTypes.
   *
   * <p>When there are 2 animation layout side by side, the default extra scale mode might leave 1 pixel not drawn between 2 animation, and
   * disabling the extraScale mode can fix this problem</p>
   *
   * <b>Attention:</b> Disable the extra scale mode can downgrade the performance and may lead to larger memory footprint. Please only disable this
   * mode when using animation with a reasonable dimension (smaller than screen size).
   *
   * @see LottieDrawable#drawWithNewAspectRatio(Canvas)
   */
  public void disableExtraScaleModeInFitXY() {
    lottieDrawable.disableExtraScaleModeInFitXY();
  }

答案 2 :(得分:0)

我遇到了同样的问题。

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>

答案 3 :(得分:0)

android:scaleType 属性添加到 com.airbnb.lottie.LottieAnimationView

<com.airbnb.lottie.LottieAnimationView
  android:id="@+id/lottieView"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:scaleType="centerCrop" // fitXY or centerCrop will resolve the aspect issue
  app:lottie_autoPlay="true"
  app:lottie_loop="false"
  app:lottie_rawRes="@raw/splash" />