2012-12-27 67 views
0

我正在開發一個黑莓項目,爲此我需要創建網格佈局。我正在研究「黑莓java sdk」。圖片數組

我使用這個代碼

public class GridScreen extends UiApplication { 
// main method 
public static void main(String[] args) { 

GridScreen theApp = new GridScreen(); 
UiApplication.getUiApplication().pushScreen(new GFMScreen()); 
theApp.enterEventDispatcher(); 

} 

} 

// VFM 
class GFMScreen extends MainScreen { 

public GFMScreen() { 

// this doesnt do anything for VCENTER!! 
//super(Field.USE_ALL_HEIGHT); 

// create a grid field manager, with 2 cols and 0 style param for super class 
// style of Manager.FIELD_VCENTER | Field.USE_ALL_HEIGHT doesnt do a thing! 
int columns = 2; 
final GridFieldManager gfm = new GridFieldManager(columns, 0); 

// add some items to the screen 
int size = 6; 
BitmapField[] fRay = new BitmapField[size]; 
for (int i = 0; i < size; i++) { 
    // create an bitmap field that's centered H + V (inside grid space) 
    fRay[i] = new BitmapField(loadBitmap("images/" + (i + 1) + ".png"), 
          Field.FIELD_HCENTER | Field.FIELD_VCENTER | Field.FOCUSABLE); 
    gfm.add(fRay[i]); 
    } 

    // set padding on top/bottom 
{ 
    // add gfm to screen - this does not center the gfm on the screen... is top aligned  no matter what! 
    add(gfm); 

    int gfmHeight = 48 * (size/columns); 
    int borderHeight = (Display.getHeight() - gfmHeight)/2; 
    gfm.setBorder(BorderFactory.createSimpleBorder(
    new XYEdges(borderHeight, 0, borderHeight, 0), 
    Border.STYLE_TRANSPARENT)); 

    System.out.println("border=" + borderHeight); 
    System.out.println("display=" + Display.getHeight()); 
    System.out.println("gfm=" + gfmHeight); 

    } 

} 

/** @param res eg "images/icon.png" */ 
public static Bitmap loadBitmap(String res) { 
    EncodedImage img = EncodedImage.getEncodedImageResource(res); 
    return img.getBitmap(); 
} 

}// end class 

什麼是錯誤的代碼? 在BlackBerry中創建網格佈局有什麼最好的方法嗎? 在上面的代碼錯誤是「Display.getHeight()沒有定義」。

+0

時發佈'code'上SO好嗎使用代碼blocks.its,我們都做了錯誤第一次(實際上是清一色jonSkeet)。 –

+0

@ MukulGoel-thanx。當然我會記得。 –

+0

你得到了什麼錯誤 –

回答

0

希望這個代碼可以幫助:

Bitmap[] images = new Bitmap[6]; 
for ((int i = 0; i < 6; i++) { 
    string filename = "images/" + String.valueOf(i + 1) + ".png"; 
    images[i] = Bitmap.getBitmapResource(filename); 
    }    
} 
+0

@ MeNoMore-我不想存儲Imagefolder中存在的所有圖像。我想創建一個圖像文件夾中存在的少數選定圖像的數組。任何幫助? –

+0

已被更新回答。 – CloudyMarble

+0

這是用於BlackBerry Java,而不是桌面Java。您的代碼使用的類(和路徑)在BlackBerry上不存在。 – Nate