2016-08-20 6 views
5

Nicht in der Lage perfekte Lösung zu finden, zum Laden eines GIF-Bild in PlatzhalterWie GIF-Bild in Platzhalter von Glide/Picasso/Ion usw.

Glide 
    .with(context) 
    .load("imageUrl") 
    .asGif() 
    .placeholder(R.drawable.gifImage) 
    .crossFade() 
    .into(imageView) 

Versuchte asGif() Eigenschaft Glide Version 3.7.0 zu laden. Aber kein Glück!

+0

Was werden Sie GIF-Bilder laden bevorzugen, aus denen Bibliothek Glide/Ion ... ich habe beide benutzt, Glide lade gif sehr langsam während Ionen 2x schneller laden als glide library..Aber in Sachen Bildqualität ist Glide besser vom Ion .... Was dein Vorschlag drauf ist @Dinesh ... –

Antwort

11

Hier ist der beste Weg ..

Glide.with(getContext()).load(item[position]) 
       .thumbnail(Glide.with(getContext()).load(R.drawable.preloader)) 
       .fitCenter() 
       .crossFade() 
       .into(imageView); 
+1

Op sollte dies als die richtige Antwort markieren – suku

4

Verwenden ProgressBar als Lade gif:

Glide.with(context). 
      load(url) 
      .listener(new RequestListener<String, GlideDrawable>() { 
       @Override 
       public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { 
        progressBar.setVisibility(View.GONE); 
        return false; 
       } 

       @Override 
       public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { 
        progressBar.setVisibility(View.GONE); 
        return false; 
       } 
      }) 
      .crossFade(1000) 
      .into(imageView); 
3

ich es unten erwähnt wie:

Die Idee ist, das gif erstellen mit transition drawables & Legen Sie den Skalierungstyp so fest, wie es der Platzhalter anfänglich benötigt & Hörer anhängen, um den Skalierungstyp wieder wie erforderlich zu ändern d durch das heruntergeladene Bild, nachdem das Bild heruntergeladen wurde. (Letzter Schritt kann übersprungen werden, wenn Sie es nicht benötigen)

//ivBuilderLogo = Target ImageView 
//Set the scale type to as required by your place holder 
//ScaleType.CENTER_INSIDE will maintain aspect ration and fit the placeholder inside the image view 
holder.ivBuilderLogo.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 

//AnimationDrawable is required when you are using transition drawables 
//You can directly send resource id to glide if your placeholder is static 
//However if you are using GIFs, it is better to create a transition drawable in xml 
//& use it as shown in this example 
AnimationDrawable animationDrawable; 
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 
    animationDrawable=(AnimationDrawable)context.getDrawable(R.drawable.anim_image_placeholder); 
else 
    animationDrawable=(AnimationDrawable)context.getResources().getDrawable(R.drawable.anim_image_placeholder); 
animationDrawable.start(); 

Glide.with(context).load(logo_url) 
        .placeholder(animationDrawable) 
        .listener(new RequestListener<String, GlideDrawable>() { 
         @Override 
         public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) 
         { 
          return false; 
         } 

         //This is invoked when your image is downloaded and is ready 
         //to be loaded to the image view 
         @Override 
         public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) 
         { 
         //This is used to remove the placeholder image from your ImageView 
         //and load the downloaded image with desired scale-type(FIT_XY in this case) 
         //Changing the scale type from 'CENTER_INSIDE' to 'FIT_XY' 
         //will stretch the placeholder for a (very) short duration, 
         //till the downloaded image is loaded 
         //setImageResource(0) removes the placeholder from the image-view 
         //before setting the scale type to FIT_XY and ensures that the UX 
         //is not spoiled, even for a (very) short duration 
          holder.ivBuilderLogo.setImageResource(0); 
          holder.ivBuilderLogo.setScaleType(ImageView.ScaleType.FIT_XY); 
          return false; 
         } 
        }) 
        .into(holder.ivBuilderLogo); 

Mein Übergang ziehbar (R.drawable.anim_image_placeholder):

(nicht erforderlich, wenn ein statisches Bild mit)

<?xml version="1.0" encoding="utf-8"?> 
<animation-list 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="false"> 
    <item android:drawable="@drawable/loading_frame1" android:duration="100" /> 
    <!--<item android:drawable="@drawable/loading_frame2" android:duration="100" />--> 
    <item android:drawable="@drawable/loading_frame3" android:duration="100" /> 
    <!--<item android:drawable="@drawable/loading_frame4" android:duration="100" />--> 
    <item android:drawable="@drawable/loading_frame5" android:duration="100" /> 
    <!--<item android:drawable="@drawable/loading_frame6" android:duration="100" />--> 
    <item android:drawable="@drawable/loading_frame7" android:duration="100" /> 
    <!--<item android:drawable="@drawable/loading_frame8" android:duration="100" />--> 
    <item android:drawable="@drawable/loading_frame9" android:duration="100" /> 
    <!--<item android:drawable="@drawable/loading_frame10" android:duration="100" />--> 
</animation-list> 
0

(static_placeholder ist, sagen wir, der erste Rahmen des GIF)

Glide... 
.load("http://...") 
.placeholder(R.drawable.static_placeholder) 
.thumbnail(Glide.with(...).load(R.raw.gif_placeholder)) 
.dontAnimate() //so there's no weird crossfade 

Platzhalter ist viel EARLI gesetzt als Thumbnail, so dass "lange" leere weiße ImageViews verhindert werden. Sie können den Platzhalter jedoch überspringen, um ihn zu vereinfachen.

oder eine andere Option verwenden AnimationDrawable (Sie Ihre GIF AnimationDrawable von here umwandeln kann):

AnimationDrawable animPlaceholder = (AnimationDrawable) ContextCompat.getDrawable(activity, R.drawable.animatedDrawable); 
animPlaceholder.start(); // probably needed 
Glide... 
.load("http://...") 
.placeholder(animPlaceholder) 

Ref: link

Verwandte Themen