16

I want to play animated gif from url in android app like imgur app. Imagur is superb and very fast. I am loading gif with webview but its not up to the mark.

user3606902
  • 829
  • 1
  • 10
  • 25

4 Answers4

17

You can use Glide to play gif on ImageView. So, let's add it to your app's gradle:

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.android.support:support-v4:23.1.1'
}

Then, create an ImageView:

<ImageView
    android:id="@+id/imageView"
    android:contentDescription="@string/content"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

In your activity:

Glide  
    .with(context) // replace with 'this' if it's in activity
    .load("http://www.google.com/.../image.gif")
    .asGif()
    .error(R.drawable.error_image) // show error drawable if the image is not a gif
    .into(R.id.imageView);

For more information, open this post Glide — Displaying Gifs & Videos.

Anggrayudi H
  • 14,977
  • 11
  • 54
  • 87
1

The easy way to display animated GIF directly from URL to your app layout is to use WebView class.

Step 1: In your layout XML

<WebView
android:id="@+id/webView"
android:layout_width="50dp"
android:layout_height="50dp"
/>

Step 2: In your Activity

WebView wb;
wb = (WebView) findViewById(R.id.webView);
wb.loadUrl("https://.......);

Step 3: In your Manifest.XML make Internet permission

<uses-permission android:name="android.permission.INTERNET" />

Step 4: In case you want to make your GIF background transparent and make GIF fit to your Layout

wb.setBackgroundColor(Color.TRANSPARENT);
wb.getSettings().setLoadWithOverviewMode(true);
wb.getSettings().setUseWideViewPort(true);
Ovais Chaudhry
  • 159
  • 1
  • 6
1

Hello everyone how asking about showing gif from url in android studio just follow my lead:

First we are about to use glide library so we need to implement the dependencie

 implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

second thing to do after sync your gradle is go the your xml and create a new imageView

 <ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/image_id"
    android:layout_centerInParent="true"/>

and finally go to your mainActivity or activity that realated to this xml : first declare ImageView and find the id in onCreate like this:

public ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    
    setContentView(R.layout.activity_main);
    imageView=findViewById(R.id.image_id);

and the last thing is using glide library to show the gif yes of course from Url :

 Glide.with(this).load("https://media.giphy.com/media/xT5LMJmXRmrn3ft04w/giphy.gif").into(imageView);

that's it but if you want to use the gif from your drawable use this line instead :

Glide.with(this).load(R.drawable.imageGif).into(imageView);

This is the Glide library here: https://github.com/bumptech/glide

jenos kon
  • 504
  • 4
  • 7
0

You can set imageview as like :

           <com.example.androidgif.GifView
            android:id="@+id/gifview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

Following this tutorial you can do it :

http://android-er.blogspot.de/2014/03/load-animated-gif-from-internet.html

arifhasnat
  • 93
  • 1
  • 2
  • 10