Android GIF loader example

Here is a very basic example of GIF loader in the android application.

GitHub link to download project for free



1- I am using android-studio 3.5.3 editor to develop this example

so let's start:-

1- Start a new project or use any existing project.

2- add the following dependencies in your app-level Gradle file.

implementation 
'pl.droidsonroids.gif:android-gif-drawable:1.2.17'

3- add mavenCentral() in allprojects under project level Gradle file.


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

}
}

4- add GifImageView in activity or fragment xml where you want to show the gif.

<pl.droidsonroids.gif.GifImageView
    android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/logo"
/>

5- if you want to use custom width and height, you are free for that.

Click here for details

6- if want to set dynamically in java file

//asset file
GifDrawable gifFromAssets = 
new GifDrawable( getAssets(), "anim.gif" );
//resource (drawable or raw)
GifDrawable gifFromResource = 
new GifDrawable( getResources(), R.drawable.anim );
//Uri
GifDrawable gifFromUri = 
new GifDrawable( contentResolver, gifUri );

No comments:

Post a Comment