2014-06-06 91 views
29

我想用畢加索在一個列表視圖中加載三個連續的圖像。使用畢加索提供的方法使得這很簡單。但是,因爲這些圖像在不同時間加載,所以圖像進入時會引起閃爍效果。例如,有時圖像2出現在圖像1之前,並且當圖像1加載時會導致不自然的結果。如果我可以將列表視圖的可見性設置爲不可見,直到所有圖像都可以顯示,那將會更好。但是,我無法找到Picasso的回調方法,它會在圖像加載完成時發出信號。畢加索圖片加載回調

有沒有人知道使用畢加索這種情況的解決方案?

謝謝

+1

@ElectronicGeek我認爲OP問這個問題的方式很好。他解釋了他在這個問題上已經做了什麼(他已經實現了圖像加載,但正在經歷閃爍)並詢問畢加索是否提供某種圖像加載回調來解決問題。那完全沒有錯。 –

回答

0

您可以使用Target對象。一旦target1收到回撥,您可以下載第二個資產,然後在target2中獲取回撥,然後觸發第三個下載。

+0

這非常浪費,並且會比並發加載花費更多的時間。 – zyamys

9

您可以實現與畢加索的回調如下所示:

ImageHandler.getSharedInstance(getApplicationContext()).load(imString).skipMemoryCache().resize(width, height).into(image, new Callback() { 
      @Override 
      public void onSuccess() { 
       layout.setVisibility(View.VISIBLE); 
      } 

      @Override 
      public void onError() { 

      } 
     }); 
} 

我ImageHandler類的實現如下所示:

public class ImageHandler { 

    private static Picasso instance; 

    public static Picasso getSharedInstance(Context context) 
    { 
     if(instance == null) 
     { 
      instance = new Picasso.Builder(context).executor(Executors.newSingleThreadExecutor()).memoryCache(Cache.NONE).indicatorsEnabled(true).build(); 
     } 
     return instance; 
    } 
} 
20

下面是一個簡單的示例如何阻止畢加索圖片加載回調:

Picasso.with(MainActivity.this) 
      .load(imageUrl) 
      .into(imageView, new com.squareup.picasso.Callback() { 
         @Override 
         public void onSuccess() { 
          //do smth when picture is loaded successfully 

         } 

         @Override 
         public void onError() { 
          //do smth when there is picture loading error 
         } 
        }); 
+0

很好用!謝啦 – Charleston