現在、タブレットと電話の両方で実行されるアプリケーションに取り組んでいます。メイン メニューの背景画像の解像度は 2000x1250 で、キャンバスの幅と高さに応じてサイズが変更されます。画像のサイズは320KB(PNG)です。ただし、解像度が 2000x1250 の場合、dalvikm アロケータは、この 1 つの背景画像になんと 30MB ものメモリを割り当てます。http://developer.android.com/training/displaying-bitmaps/load-bitmap.htmlの記事を読んで適用しましたが、解像度が 2000x1250 の場合、配置されているメモリの量は同じままです (私はこれを私の解像度 1280x720 の S3)。これは私が心配すべきことですか?タブレットには、より大きなビットマップ用のスペースがありますか?
前もって感謝します、-Z
EDIT1:
ログキャット
申し込み開始
02-08 20:35:12.105: D/dalvikvm(27962): GC_FOR_ALLOC 解放 8804K、18% 解放 53293K/64775K、一時停止 31ms、合計 31ms
02-08 20:35:12.110: I/dalvikvm-heap(27962): 9000016 バイトの割り当てのために、ヒープ (フラグ ケース) を 61.693MB に拡張します
02-08 20:35:12.145: D/dalvikvm(27962): GC_CONCURRENT 解放 35206K、59% 解放 26875K/64775K、一時停止 11ms+3ms、合計 32ms
02-08 20:35:12.315: D/dalvikvm(27962): GC_FOR_ALLOC 解放 0K、59% 解放 26875K/64775K、一時停止 10ms、合計 10ms
これは、メインメニューが開いている場所ですendend
02-08 20:35:12.330: I/dalvikvm-heap(27962): ヒープ (frag ケース) を 61.643MB に拡張し、36000016 バイトの割り当てを行う
02-08 20:35:12.350: D/dalvikvm(27962): GC_CONCURRENT 解放 0K、5% 解放 62031K/64775K、一時停止 11ms+3ms、合計 23ms
チュートリアルの関数:
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
// Calculate ratios of height and width to requested height and width
final int heightRatio = Math.round((float) height / (float) reqHeight);
final int widthRatio = Math.round((float) width / (float) reqWidth);
// Choose the smallest ratio as inSampleSize value, this will guarantee
// a final image with both dimensions larger than or equal to the
// requested height and width.
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
return inSampleSize;
}
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
OnCreate の私のコード (非推奨であることは気にしないでください。それは問題ではありません):
final FrameLayout fr = (FrameLayout) findViewById(R.id.mainmenu_background);
//fr.setBackgroundResource(R.drawable.background_main_menu);
Display display = getWindowManager().getDefaultDisplay();
//Point size = new Point();
//display.getSize(size);
fr.setBackgroundDrawable(new BitmapDrawable(getResources(), decodeSampledBitmapFromResource(getResources(), R.drawable.background_main_menu, 2000, 1250)));
XML のコード:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainmenu_background"
>
何か案は?