How to load GIF image from hand-drawn folder in ImageView using slide?

I need to show a loading GIF image using drawable to ImageView with glide. I tried with the following.

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

But it doesn’t work and works when I put the image in a folder raw. But the problem is that I have to use different dimensional images.

Any help would be greatly appreciated.

+4
source share
5 answers

You can try using Ion, it works great 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

Glide 3.0 asGif() :

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

, load() GIF Bitmap . , , URL gif, asGif()

+8

load():

Glide.with(LoginActivity.this)
            .load(R.drawable.bg_gif)
            .asGif()  // you may not need this
            .crossFade()
            .into(relativeLayout);
+4

Gif

  • Gif res/raw ( raw , gif)

  • , gif

Glide.with(this)
                  .load(R.raw.splash)
                  .into(new GlideDrawableImageViewTarget(
                          (ImageView) findViewById(R.id.image)));
+2

Gif "raw"

  GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
    Glide.with(this).load(R.raw.test).into(imageViewTarget);
+1

Glide 4

GlideApp.with(this)
            .load(R.raw.gif_file)
            .diskCacheStrategy(DiskCacheStrategy.NONE)
            .into(imageView);
0

Source: https://habr.com/ru/post/1629518/


All Articles