简体   繁体   中英

GIF doesn't appear when Android app starts

I'm having trouble with a GIF that I'm trying to use in my app. When I run my app it simply just doesn't appear. I followed tutorials on how to make it work so I have no idea why it doesn't. I also don't get any error messages either. So, my question is does anyone have any suggestions on why this is happening? Thanks in advance for any help!

My code:

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" />

I strongly recommend you to implement Lottie instead. It supports a different kind of formats and autoPlay feature also.

https://github.com/airbnb/lottie-android

<com.airbnb.lottie.LottieAnimationView
            android:id="@+id/lavSplash"
            app:lottie_rawRes="@raw/splash"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            style="@style/Widget.Custom.Lottie"/>

<style name="LottieAppearance">
        <item name="lottie_loop">true</item>
        <item name="lottie_autoPlay">true</item>
        <item name="android:layout_width">@dimen/wrap_content</item>
        <item name="android:layout_height">@dimen/wrap_content</item>
</style>

<style name="Widget.Custom.Lottie" parent="LottieAppearance" />

TRY THIS:

 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();
                }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM