Skip to content Skip to sidebar Skip to footer

Using Glide To Load A Placeholder From Url To Display While Loading A Gif (android)

What I have is this: Glide .with(this) .load(imageUrl) .asGif() .diskCacheStrategy(DiskCacheStrategy.SOURCE) .placeholde

Solution 1:

You have to pass the URL in .thumbnail(url) as

.thumbnail(Glide
        .with(context)
        .load(Url)
        .asBitmap()

Or like this:-

DrawableRequestBuilder<String> thumbnail = Glide.with(context)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .load(url);
    try {
        Glide.with(context)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .error(placeholder)
                .load(url)
                .thumbnail(thumbnail)
                .into(imageView);
    } catch (Exception e) {
        e.printStackTrace();
    }

Reference:

https://github.com/bumptech/glide/issues/1198

https://futurestud.io/tutorials/glide-thumbnails

https://github.com/bumptech/glide/issues/362

privatevoidloadImage(ImageView image, @RawRes int typeID, String imagePath) {
Context context = image.getContext();
BitmapPool pool = Glide.get(context).getBitmapPool();

// OPTION 1 Bitmap
Glide
    .with(image.getContext())
    .load(imagePath)
    .asBitmap()
    .animate(android.R.anim.fade_in)
    .placeholder(R.drawable.image_loading)
    .error(R.drawable.image_error)
    .thumbnail(Glide
        .with(context)
        .load(typeID)
        .asBitmap()
        .imageDecoder(new SvgBitmapDecoder(pool)) // implements ResourceDecoder<InputStream, Bitmap>
    )
    .into(image)
;

// OPTION 2 GlideDrawable
Glide
    .with(image.getContext())
    .load(imagePath)
    .crossFade()
    .placeholder(R.drawable.image_loading)
    .error(R.drawable.image_error)
    .thumbnail(Glide
        .with(context)
        .load(typeID)
        .decoder(new GifBitmapWrapperResourceDecoder(
                    new ImageVideoBitmapDecoder(
                        new SvgBitmapDecoder(pool),
                        null/*fileDescriptorDecoder*/
                    ),
                    // just to satisfy GifBitmapWrapperResourceDecoder.getId() which throws NPE otherwisenew GifResourceDecoder(context, pool),
                    pool
                )
        )
    )
    .into(image)
;
}

Post a Comment for "Using Glide To Load A Placeholder From Url To Display While Loading A Gif (android)"