2010-10-22 36 views
3

加入數組列表的詳細圖片我開始遊戲開發將位圖圖像中數組列表怎麼能實現如何能在Android的

for(int i =0;i<9;i++) 
{ 
    resizedBitmap[i] = Bitmap.createBitmap(bitmapOrg, (i%3)*newWidth, (i/3)*newHeight,newWidth, newHeight);    
} 

鑑於9個圖像存儲陣列列表顯示隨機順序如何能實現其緊急

+0

它是一個拼圖遊戲,對不對? :) – st0le 2010-10-22 11:34:18

+0

是這個益智遊戲的目的可以請發送一些源代碼相關的這些鏈接 – Narasimha 2010-10-22 11:48:22

回答

2

有很多方法可以實現您試圖實現的目標。 其中一種方法是拋棄數組,然後使用ArrayList。

ArrayList<Bitmap> mBitmaps = new ArrayList<Bitmap>(9); 
for (int i = 0; i < 9; i++) 
{ 
    mBitmaps.add(Bitmap.createBitmap(bitmapOrg, (i % 3) * newWidth, (i/3) * newHeight, newWidth, newHeight)); 
} 

Collections.shuffle(mBitmaps); 

for (int i = 0; i < 9; i++) 
{ 
    Bitmap bitmap = mBitmaps.get(i)); 

    //Do something 
    //... 
} 
+0

非常感謝你先生,其工作正常 – Narasimha 2010-10-25 05:52:06

+0

我有28名圖像名稱startimg01到28分別。我如何添加這些圖像speciallty? – 2010-11-16 09:41:44

+0

如果您的意思是您想通過名稱而不是索引來調用這些圖像,則可以使用Map 而不是數組。要添加:mBitmaps.put(「img01」,bitmap);檢索:位圖位圖= mBitmaps.get(「img01」); – 2010-11-18 05:34:33