Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load GIF image from drawable folder into ImageView using glide?

I have to show load GIF image from drawable to ImageView using glide.I have tried with following.

Glide.with(LoginActivity.this)
                .load(getResources().getDrawable(R.drawable.bg_gif)).asGif()
                .crossFade()
                .into(relativeLayout);

But isn't seem working and it's working when I'm place image in raw folder.but the problem is I have to use different dimension images.

Any help would be greatly appreciated.

like image 430
Stella Avatar asked Feb 19 '16 07:02

Stella


People also ask

Can we show GIF in ImageView in Android?

Here we are loading the gif using ImageView and Glide Library. Insert the following dependency to build. gradle file of your project. Navigate to the app > res > layout > activity_main.

How do you add drawable images to glide Android?

into(myImageView); Load method of Glide also accept drawable object as a parameter to load image. You just have to get the drawable object from your drawable image and pass it to the load method.


2 Answers

You can try to use Ion it works fine for me. Ion

Using Ion

 Ion.with(imgView)
.error(R.drawable.default_image)
.animateGif(AnimateGifMode.ANIMATE)
.load("file:///android_asset/animated.gif");

Using Glide

ImageView imageView = (ImageView) findViewById(R.id.imageView);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(this).load(R.raw.sample_gif).into(imageViewTarget);

Another Approach

For Glide 3.0 you need to set asGif() earlier:

Glide.with(context)
    .load(imageUrl)
    .asGif()
    .placeholder(R.drawable.loading2)
    .crossFade()
    .into(imageView);

Keep in mind that just using load() will load either a GIF or a Bitmap depending on the type of the data. Unless you want your load to fail if the given url is not a gif, you don't need to specify asGif()

like image 118
Kristo Avatar answered Nov 14 '22 14:11

Kristo


Just pass the resource id directly to load():

Glide.with(LoginActivity.this)
            .load(R.drawable.bg_gif)
            .asGif()  // you may not need this
            .crossFade()
            .into(relativeLayout);
like image 28
Doug Stevenson Avatar answered Nov 14 '22 13:11

Doug Stevenson