0

我正在開發Android 3.1平板電腦應用程序。在顯示活動視圖後將圖像加載到圖庫中

我需要加載並顯示存儲在本地磁盤中的一些圖像。知道UI會在圖像加載時凍結,並顯示在畫廊上,我想知道是否有另一種方式顯示UI,並顯示UI時,顯示ProgressDialog,然後開始從磁盤加載並顯示每張圖像。

我知道如何開始和Asyntask但我不知道如何做一些事情後,顯示。

我把task.execute()OnCreateOnResume,我看到UI凍結。

如何在顯示UI後執行任務?

如果您需要查看代碼,請檢查Gallery images still load very slowClassCastException: AbsListView$LayoutParams cannot be cast to Gallery$LayoutParams問題。

+0

爲了理解這個問題,你需要一個圖庫加載內存的圖像?他們已經下載了嗎?你爲什麼需要asynctask?只是爲了展示他們?順便說一句,畫廊已棄用,爲什麼不使用horizo​​ntalScroolView或viewpager? –

+0

不,我有一個'ArrayList '圖像的路徑。我將從本地磁盤加載這些圖像,並且它們位於本地磁盤上。我是Android開發新手,我不知道Gallery已被棄用。 – VansFannel

+0

本地磁盤是什麼意思?我以爲你有他們的手機內存或卡? –

回答

0

首先你應該有一個活動與你的圖庫(或任何你決定使用)和一個圖庫適配器。在適配器的getView()中,您應該加載一個圖像(getView()是每個圖庫對象的圖庫)。 對於加載,你應該有這樣的方法:

public static Bitmap loadFromPath(String file_path) { 
    BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inDither = false; // disable dithering 
    options.inScaled = false; // do not scale bitmap when loading; scale later 
    options.inPreferredConfig = Bitmap.Config.ARGB_8888; 
    Bitmap backgroundBitmap = null; 
    try { 
     backgroundBitmap = BitmapFactory.decodeFile(file_path, options); 
    } catch (OutOfMemoryError e) { 
      e.printStackTrace(); 
    } 
    return backgroundBitmap; 

}

該返回位圖,您可以使用設置的ImageView源getView()。 如果您有問題,請告訴我!

+0

你有試過嗎?它工作嗎? –

相關問題