2017-08-29 102 views
0

我有一個應用程序包含一系列圖像通過鏈接使用滑翔庫出現,我的應用程序需要很長時間才能加載所有圖像,因此可以通過圖像加載圖像(一個接一個)。如何使用Glide Library通過圖像加載圖像?

Glide.with(context) 
    .load(imageId.get(position)) 
    .diskCacheStrategy(DiskCacheStrategy.ALL) 
    .priority(Priority.HIGH) 
    .listener(new RequestListener<String, GlideDrawable>() { 
     @Override 
     public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { 
      return false; 
     } 
     @Override 
     public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { 
      progressBar.setVisibility(View.GONE); 
      return false; 
     } 
    }) 
    .into(holder.CategoryImage); 
+1

你在哪裏把這個代碼?它在適配器getview中嗎? –

+0

@編程海盜是在'getview()' – MrMR

+1

你的圖像大小是多少?它們是大圖像還是縮略圖 –

回答

2

試試這個

Glide.with(context) 
     .load(imageId.get(position)) 
     .diskCacheStrategy(DiskCacheStrategy.ALL) 
     .priority(Priority.HIGH) 
     .listener(new RequestListener<String, GlideDrawable>() { 
      @Override 
      public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { 
        return false; 
      } 
      @Override 
      public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { 
       progressBar.setVisibility(View.GONE); 
       return false; 
      } 
     }) 
     .thumbnail(0.1f) // this will do the trick 
     .into(holder.CategoryImage); 

,如果它不能正常工作,嘗試這種方式,

Glide.with(context) 
     .load(imageId.get(position)) 
     .diskCacheStrategy(DiskCacheStrategy.ALL) 
     .priority(Priority.HIGH) 
     .override(100,100) 
     .listener(new RequestListener<String, GlideDrawable>() { 
      @Override 
      public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { 
        return false; 
      } 
      @Override 
      public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { 
       progressBar.setVisibility(View.GONE); 
       Glide.with(context).load(imageId.get(position)) 
        .diskCacheStrategy(DiskCacheStrategy.ALL) 
        .priority(Priority.HIGH) 
        .into(holder.CategoryImage); 
       return false; 
      } 
     }) 
     .into(holder.CategoryImage); 
相關問題