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.
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.
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.
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()
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With