7

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.

Stella
  • 1,817
  • 6
  • 30
  • 55

5 Answers5

15

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()

Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103
Kristo
  • 1,339
  • 12
  • 22
8

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);
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • It works perfectly fine for me - I did write the code and execute it. You may want to consider if your ImageView is correctly visible. – Doug Stevenson Feb 19 '16 at 08:10
3

Steps to load Gif images from drawable

  1. You need to move your Gif image tores/raw folder of your project ( if your project don't have raw folder in resource directly then simply make one and put your gif in it )

  2. and then you can simply load your gif with just one line of code

Glide.with(this)
                  .load(R.raw.splash)
                  .into(new GlideDrawableImageViewTarget(
                          (ImageView) findViewById(R.id.image)));
Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
1

Place your Gif in the "raw" folder and use

  GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
    Glide.with(this).load(R.raw.test).into(imageViewTarget);
J. Chomel
  • 8,193
  • 15
  • 41
  • 69
Satyam Anand
  • 377
  • 1
  • 8
1

For Glide 4

GlideApp.with(this)
            .load(R.raw.gif_file)
            .diskCacheStrategy(DiskCacheStrategy.NONE)
            .into(imageView);
Gowsik
  • 1,096
  • 1
  • 12
  • 25