0

このコードをループする方法である必要があります。

private void loadSprites() {
    this.sprites[0] = BitmapFactory.decodeResource(getResources(), R.drawable.ic_boom01);
    this.sprites[1] = BitmapFactory.decodeResource(getResources(), R.drawable.ic_boom02);
    this.sprites[2] = BitmapFactory.decodeResource(getResources(), R.drawable.ic_boom03);
    this.sprites[3] = BitmapFactory.decodeResource(getResources(), R.drawable.ic_boom04);
    this.sprites[4] = BitmapFactory.decodeResource(getResources(), R.drawable.ic_boom05);
    this.sprites[5] = BitmapFactory.decodeResource(getResources(), R.drawable.ic_boom06);
    this.sprites[6] = BitmapFactory.decodeResource(getResources(), R.drawable.ic_boom07);
}

ありがとう!

4

5 に答える 5

2

私があなたの質問を理解しているなら、あなたは次のようなものが欲しいです、

int[] drawables = {R.drawable.ic_boom01,R.drawable.ic_boom02,R.drawable.ic_boom03,R.drawable.ic_boom04,R.drawable.ic_boom05,R.drawable.ic_boom06,R.drawable.ic_boom07}


private void loadSprites() {
for(int i=0; i<this.sprites.length; i++)
    this.sprites[i] = BitmapFactory.decodeResource(getResources(), drawables[i]);
}
于 2012-06-22T08:57:25.193 に答える
1

画像は assets フォルダーに配置する必要があります。それらから、ファイル名を介してアクセスできます。http://developer.android.com/reference/android/content/res/AssetManager.htmlを参照してください。

于 2012-06-22T08:54:41.907 に答える
0

そのためには、以下のコードを見てください。

最初に int 配列を作成します

int[] mImgArray = { R.drawable.ic_boom01, R.drawable.ic_boom02,
            R.drawable.ic_boom03, R.drawable.ic_boom04, R.drawable.ic_boom05,
            R.drawable.ic_boom06, R.drawable.ic_boom07 };

または以下のコードを使用して、この画像を ImageView に設定します

mImgView1.setImageResource(mImgArray[0]);

また、この画像を直接ビットマップに変換し、以下のコードを使用してビットマップ配列に保存できます。

Bitmap mBmpArray=new Bitmap[mImgArray.length];
for(int i=0; i<mImgArray.length; i++)
    mBmpArray[i] = BitmapFactory.decodeResource(getResources(), mImgArray[i]);
}
于 2012-06-22T09:04:09.523 に答える
-1

単純な for ループでそれを行うことができます..最初の id から開始し、ループごとに 1 ずつ増やします..これを行うことはお勧めしません..

于 2012-06-22T08:55:43.807 に答える