2017-07-07 1 views
1

Guten Tag.Verwenden von Glide, um einen Platzhalter aus der URL zu laden, während ein GIF geladen wird (Android)

Was ich habe, ist dies:

Glide 
      .with(this) 
      .load(imageUrl) 
      .asGif() 
      .diskCacheStrategy(DiskCacheStrategy.SOURCE) 
      .placeholder(R.drawable.gif) 
      .into(imageView); 

Aber anstatt, ich will Glide verwenden, um das gleiche gif asBitmap() für als Platzhalter verwenden zu laden, während es die tatsächliche GIFs geladen.

Wie, wenn ich tun kann: .placeholder(Glide.with(this).load(imageUrl).asBitmap())

Vielen Dank im Voraus.

Antwort

1

Sie haben die URL in .thumbnail (url) als

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

Oder so passieren: -

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

Referenz:

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

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

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

private void loadImage(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 otherwise 
        new GifResourceDecoder(context, pool), 
        pool 
       ) 
     ) 
    ) 
    .into(image) 
; 
} 
Verwandte Themen