Search code examples
androidandroid-studioanimated-gif

How to make gif image appear as splash screen


I want to show gif image in my android application as a splash for five seconds(without using webview). If I am using ImageView, and adding Gif to it, it is not showing as general Image.Please help regarding this.


Solution

  • 1.Put compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'

    in your build.gradle file as dependency.

    1. Put your .gif file in the drawable folder

    Call the below method in onCreate of your SplashActivity

    public void startSplash(){
            Animation fadeout = new AlphaAnimation(1.f, 1.f);
            fadeout.setDuration(2500);
            final View viewToAnimate = gifImageView;
            fadeout.setAnimationListener(new Animation.AnimationListener() {
    
                @Override
                public void onAnimationStart(Animation animation) {
                    gifImageView.setBackgroundResource(R.drawable.splash_screen);//splash_screen is your .gif file
                }
    
                @Override
                public void onAnimationRepeat(Animation animation) {
                }
    
                @Override
                public void onAnimationEnd(Animation animation) {
    
            });
            gifImageView.startAnimation(fadeout);
        }
    
    
     Put the below code in your SplashActivty.xml
    
         <pl.droidsonroids.gif.GifTextView
                    android:id="@+id/imageView"
                    android:layout_width="fill_parent"
                    android:scaleType="fitXY"
                    android:layout_height="fill_parent"
                    />
    

    Go to your Project Level build.gradle file and add the below code if its not there

    buildscript {
        repositories {
            mavenCentral()
        }
    }
    allprojects {
        repositories {
            mavenCentral()
        }
    }
    

    Or You can also try

    repositories {
        jcenter()
    }