【问题标题】:Strange Behaviour on Lottie Animation ViewLottie 动画视图上的奇怪行为
【发布时间】:2021-07-31 03:17:18
【问题描述】:

所以我有 Lottie animationView 的闪屏和下面的 xml 文件

但 IDE 说

Cannot resolve class com.airbnb.lottie.LottieAnimationView

问题是我可以在调试和 Splash 内容中运行我的应用程序,完美地显示内容 当我想在发布版本中构建时它不能因为错误:LottieAnimationView 必须扩展 android.view.View [Instantiatable]

我正在关注此处列出的官方文档official lottie doc 并且没有任何问题,并且在调试版本中显示 Splash

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.airbnb.lottie.LottieAnimationView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:lottie_autoPlay="true"
        app:lottie_rawRes="@raw/splash_cat"
        app:lottie_loop="true"
        app:lottie_speed="1.00" />

</androidx.constraintlayout.widget.ConstraintLayout>

edit1:我正在使用颤振并遵循此示例flutter Lottie Splash

【问题讨论】:

    标签: android xml flutter kotlin lottie


    【解决方案1】:

    试试这个

    第一部分:

        <?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"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    
            <com.airbnb.lottie.LottieAnimationView
                android:id="@+id/progressAnimationView"
                android:layout_width="270dp"
                android:layout_height="196dp"
                android:layout_centerInParent="true"
                android:layout_marginTop="80dp"
                android:padding="5dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.553"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:lottie_autoPlay="true"
                app:lottie_fileName="splash_cat.json"    
                app:lottie_loop="true" />
    
    
          </androidx.constraintlayout.widget.ConstraintLayout>
    

    第二部分: 现在在程序代码部分,你可以通过这种方式再次看到你的动画文件的地址

    在主活动中

            private LottieAnimationView lottieAnimationView;  //global define 
            .
            .
            .
    

    in onCreate() //Activity或者onCreateView Fragment

            lottieAnimationView = findViewById(R.id.progressAnimationView);
            lottieAnimationView.setAnimation(R.raw.splash_cat);
    

    【讨论】:

    • 我可以把它放在哪里?这是我的 splashView.kt ~import android.content.Context import android.os.Bundle import android.view.LayoutInflater import android.view.View import io.flutter.embedding.android.SplashScreen class SplashView : SplashScreen { override fun createSplashView(上下文:上下文,已保存实例状态:捆绑?):查看? = LayoutInflater.from(context).inflate(R.layout.splash_view, null, false) 覆盖有趣的 transitionToFlutter(onTransitionComplete: Runnable) { onTransitionComplete.run() } }~
    • 你不想写第二部分,用我放的相同的 XML 代码测试它
    • 我在我的主要活动中尝试过,但无法输入它,因为那是 java 代码,我的 android studio 强迫我重构它
    【解决方案2】:

    我经历过,我所做的是重新实现最新的lottie版本和gradle,然后清理项目并重建项目。

    【讨论】:

    • 我的 Lottie 版本是 4.0.0(最新),由于 3.7.0 仍然遇到此错误,我将尝试清理项目
    • 您是否尝试过添加 .行家{网址'maven.google.com'}。在您的构建 .gradle 项目中?
    • 不,问题不在于找到包,但 android studio 想让我实例化那个类
    猜你喜欢
    • 1970-01-01
    • 2015-01-08
    • 1970-01-01
    • 2023-03-11
    • 2019-10-09
    • 2016-08-29
    • 1970-01-01
    • 1970-01-01
    • 2019-01-10
    相关资源
    最近更新 更多