2016-09-22 57 views

回答

2

使用通用圖像裝載機,最好的辦法是創造了什麼一個實例,當您的應用程序啓動,然後在整個應用程序中獲取該實例

這裏是應用程序類

public class App extends Application { 

    public ImageLoader imageLoader; 

    public ImageLoader getImageLoader() { 
     return imageLoader; 
    } 

    @Override 
    public void onCreate() { 
     super.onCreate(); 

     // UNIVERSAL IMAGE LOADER SETUP 
     DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() 
       .resetViewBeforeLoading(true) 
       .cacheOnDisk(true) 
       .cacheInMemory(true) 
       .displayer(new FadeInBitmapDisplayer(300)) 
       .build(); 

     ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) 
       .defaultDisplayImageOptions(defaultOptions) 
       .memoryCache(new WeakMemoryCache()) 
       .diskCacheSize(100 * 1024 * 1024) 
       .build(); 

     this.imageLoader = ImageLoader.getInstance(); 
     imageLoader.init(config); 

     // END - UNIVERSAL IMAGE LOADER SETUP 
    } 
} 

確保在AndroidManifest.xml應用程序標記有機器人:名字=」應用程序」屬性

來獲得實例,在活動

ImageLoader imageLoader = ((App)getApplicationContext()).getImageLoader(); 

外活動

ImageLoader imageLoader = ((App)context.getApplicationContext()).getImageLoader(); 

您可以參考this博客。

3

ImageLoader.getInstance(); // Get singleton instance 上述行將提供一個單例。你可以調用它然後執行你的加載 作爲doc顯示有一個sample project你可以從github下載表格。此示例項目顯示如何正確使用此庫

1

我建議您使用Glide一個非常漂亮的圖像加載器庫,我自己試過並樂於使用它。

這是你需要閱讀和執行圖像緩存和高效利用的lib

https://futurestud.io/tutorials/glide-getting-started

官方鏈接 https://github.com/bumptech/glide

+0

我可以使用glide從遠程源獲取視頻縮略圖嗎? –

+0

@TunahanBayındır是的,你可以使用滑行的裝載網址,它加載的URL,並在存儲器中保存大量的內存 –

+0

@緩存它darpan-S-raut我的意思是,它可以得到一個遠程視頻作爲縮略圖的第一幀? –

相關問題