首页 > 解决方案 > 在 Android 的 Surface View 游戏循环中实现 Lottie 动画

问题描述

好的,所以我现在面临的主要问题是,我们知道将子视图添加到表面视图中,我们只能绘制,所以我实现了一个扩展表面视图的自定义视图,现在为了向其中添加子视图,我已经从xml 使用布局充气器和表面视图的 onDraw 方法我已经绘制了它,但问题是 Lottie 动画无法正确显示。

自定义视图

public class CustomView extends SurfaceView implements SurfaceHolder.Callback, Runnable {

    @Override
    public void run() {
       
      //Draw onto canvas
       
       

    }


}

动画视图.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:layout_width="@dimen/dimen_150"
    android:layout_height="@dimen/dimen_150">

    <com.airbnb.lottie.LottieAnimationView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="visible"
        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_loop="false"
        app:lottie_rawRes="@raw/score_counter_green"/>

    <TextView
        android:id="@+id/HeadingTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:fontFamily="@font/monospec_medium"
        android:text="@string/heading_score"
        android:textColor="@color/colorWhite"
        android:textSize="@dimen/text_size_15"
        android:textStyle="bold|italic"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

标签: androidanimationlottie

解决方案


推荐阅读