首页 > 解决方案 > Android 应用启动时不显示 GIF

问题描述

我在尝试在我的应用程序中使用 GIF 时遇到问题。当我运行我的应用程序时,它根本不会出现。我遵循了有关如何使其工作的教程,所以我不知道为什么它不工作。我也没有收到任何错误消息。所以,我的问题是,有人对为什么会发生这种情况有任何建议吗?提前感谢您的帮助!

我的代码:

buildscript {

    repositories {
        mavenCentral()
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'



    }
}

allprojects 
{
    repositories
 {
        mavenCentral()
        google()
        jcenter()


    }
}


App build script:

dependencies {


    implementation  'pl.droidsonroids.gif:android-gif-drawable:1.2.16'
}

XML:
    <pl.droidsonroids.gif.GifImageView
        android:layout_width="match_parent"
        android:layout_height="60dp"
        app:srcCompat="@drawable/gif" />

标签: javaandroidgif

解决方案


尝试这个:

 XML:

   <pl.droidsonroids.gif.GifImageView
                android:id="@+id/gif_view_offer"
                android:layout_gravity="center"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_marginTop="20dp"
                android:src="@drawable/checkmark"
                android:layout_marginBottom="10dp"/>




 JAVA:

       GifImageView gifView;
                GifDrawable gifFromResource = null;

                gifView = (GifImageView) v.findViewById(R.id.gif_view_offer);
                try {
                    gifFromResource = new GifDrawable(activity.getResources(), R.drawable.lockgif);
                    gifView.setImageDrawable(gifFromResource);
                } catch (IOException e) {
                    gifView.setVisibility(View.GONE);
                    e.printStackTrace();
                }

推荐阅读