Android圖片緩衝的架構ImageLoader的使用

來源:互聯網
上載者:User

標籤:

DisplayImageOptions options;        // DisplayImageOptions是用於設定圖片顯示的類

// 使用DisplayImageOptions.Builder()建立DisplayImageOptions  
options = new DisplayImageOptions.Builder()  
.showStubImage(R.drawable.ic_stub)          // 設定圖片下載期間顯示的圖片  
.showImageForEmptyUri(R.drawable.ic_empty)  // 設定圖片Uri為空白或是錯誤的時候顯示的圖片  
.showImageOnFail(R.drawable.ic_error)       // 設定圖片載入或解碼過程中發生錯誤顯示的圖片      
.cacheInMemory(true)                        // 設定下載的圖片是否緩衝在記憶體中  
.cacheOnDisc(true)                          // 設定下載的圖片是否緩衝在SD卡中  
.displayer(new RoundedBitmapDisplayer(20))  // 設定成圓角圖片  
.build();                                   // 建立配置過得DisplayImageOption對象

private ImageLoadingListener animateFirstListener = new AnimateFirstDisplayListener();

/**
 * 圖片載入第一次顯示監聽器
 * @author Administrator
 *
 */  
private static class AnimateFirstDisplayListener extends SimpleImageLoadingListener {  
          
static final List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>()); 
@Override  
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {  
    if (loadedImage != null) {  
       ImageView imageView = (ImageView) view;  
       // 是否第一次顯示  
       boolean firstDisplay = !displayedImages.contains(imageUri);  
       if (firstDisplay) {  
             // 圖片淡入效果  
             FadeInBitmapDisplayer.animate(imageView, 500);  
             displayedImages.add(imageUri);  
         }  
       }  
    }  
}

/**
 * 顯示圖片
 * 參數1:圖片url
 * 參數2:顯示圖片的控制項
 * 參數3:顯示圖片的設定
 * 參數4:監聽器
 */  
imageLoader.displayImage(imageUrls[position], holder.image, options, animateFirstListener);

 

詳細的可以參考部落格:

http://blog.csdn.net/wwj_748/article/details/10079311

 

Android圖片緩衝的架構ImageLoader的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.