Android tutorial

How to use GIF image on Splash Screen In Android

GIF image on Splash Screen

Hi Everyone in this Article I am sharing how to use GIF image on Splash Screen in android. We will make gif splash screen in android studio in today’s example.

You can make really great animated and attractive splash screen with GIF. GIF provides seamless animation to the first impression of any android application. It is very easy to make Android Splash Screen Animation.

Following are the necessary steps to create a gif Android Splash Screen Animation.GIF Splash Screen In Android Studio

How to use GIF image on Splash Screen In Android

Step 1. Adding Library in build gradel

This project requires a third-party library to show the gif file in an XML layout file. So that you can add below dependencies in your app base build gradel. We will use this GitHub library: android-gif-drawable

Write below the line in the build.gradle(Module: app) file

dependencies {

    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.8.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.17'
 
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

}

After adding these dependencies you can sync your project and get the all method of the librarby.

Now it is time to play with GIF file.

  • Android has different layouts for different display factors. For example, image view for image or picture, Textview for string, Button for the clickable button, Edittext for input box, etc.
  • But it has not any in a built widget for GIF. Hence, we have to create it on our own.
  • This is where that Github library will help us

<pl.droidsonroids.gif.GifImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/splesh_screen"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    />

Step 2. Create a Splash Screen Activity.

Open You Activity XML File and add these code activity_splash_screen.xml.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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="match_parent"
    android:layout_height="match_parent"
    tools:context=".activity.SplashActivity"
    android:background="#15489e">


    <pl.droidsonroids.gif.GifImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/splesh_screen"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        />

</RelativeLayout>

Step 3. After Add these codes add a GIf in your Drawable Folder. res==> drawable  GIF Splash Screen In Android Studio Animated

add a gif in this folder

 

Step 4. After Add gif Open Your Java File Splash_Screen.java and add these code.

  • This line defines the time for which you want to show the splash screen to the user.
  • Here I have set it as the 8000 milliseconds which means that the splash screen will be shown for the 8 seconds.
  • You can change the time interval from this line as per your requirements.

 

public class SplashActivity extends AppCompatActivity {
    private final int SPLASH_DISPLAY_LENGTH = 8000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

         /* New Handler to start the Menu-Activity
         * and close this Splash-Screen after some seconds.*/
        new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
                /* Create an Intent that will start the Menu-Activity. */
                Intent mainIntent = new Intent(SplashActivity.this,LoginActivity.class);
                SplashActivity.this.startActivity(mainIntent);
                SplashActivity.this.finish();
            }
        }, SPLASH_DISPLAY_LENGTH);
    }


Read More Tutorial