2016-08-20 18 views
5

भीकैसे की प्लेसहोल्डर में gif छवि को लोड करने ग्लाइड/पिकासो/आयन आदि

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

की कोशिश की asGif() ग्लाइड संस्करण 3.7.0 की संपत्ति प्लेसहोल्डर में एक gif छवि लोड करने के लिए एकदम सही समाधान खोजने के लिए सक्षम नहीं है। लेकिन कोई भाग्य नहीं!

+0

क्या आप gif छवियों को लोड करने के लिए पसंद करेंगे जो पुस्तकालय ग्लाइड/आयन से ... मैंने दोनों का उपयोग किया है, ग्लाइड लोड gif बहुत धीमी है जबकि आयन ग्लाइड लाइब्रेरी की तुलना में 2x गुना तेज है .. लेकिन छवि गुणवत्ता के मामले में ग्लाइड आयन से बेहतर है .... @Dinesh पर आपका सुझाव क्या है ... –

उत्तर

11
यहाँ

बेस्ट तरीका है ..

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

ओप को इसे सही उत्तर के रूप में चिह्नित करना चाहिए – suku

4

उपयोग ProgressBar लोड हो रहा है 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

मैं क्या यह नीचे उल्लेख पसंद:

विचार का उपयोग कर gif बनाने के लिए है transition drawables & स्थान धारक द्वारा आवश्यक रूप से स्केल प्रकार को सेट करें & स्केल प्रकार को फिर से बदलने के लिए श्रोता को संलग्न करें छवि डाउनलोड होने के बाद डाउनलोड की गई छवि से डी। (अंतिम चरण यदि आप इसे की आवश्यकता नहीं है छोड़ा जा सकता है)

//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); 

मेरे संक्रमण drawable (R.drawable.anim_image_placeholder):

<?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

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

प्लेसहोल्डर सेट किया गया है ज्यादा earli (static_placeholder, GIF के पहले फ्रेम है कहते हैं,) थंबनेल से एर, इसलिए यह "लंबे" खाली सफेद छवि दृश्यों को रोकता है। हालांकि प्लेसहोल्डर को सरल बनाने के लिए आप छोड़ सकते हैं।

या किसी अन्य विकल्प का उपयोग करने के AnimationDrawable (आप here से AnimationDrawable करने के लिए अपने GIF परिवर्तित कर सकते हैं) है:

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

रेफरी: link

संबंधित मुद्दे