エラー:
java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:618)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:593)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:445)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:775)
at android.content.res.Resources.loadDrawable(Resources.java:1968)
at android.content.res.Resources.getDrawable(Resources.java:677)
at android.widget.ImageView.resolveUri(ImageView.java:542)
at android.widget.ImageView.setImageResource(ImageView.java:315)
at app.Main.GridActivity.initaliseLevel(GridActivity.java:245)
at app.Main.GridActivity.load_player_settings(GridActivity.java:180)
at app.Main.GridActivity.onResume(GridActivity.java:79)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1158)
at android.app.Activity.performResume(Activity.java:4607)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2448)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2486)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2000)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
画像は次のように設定されます。
ImageButton b0 = (ImageButton) findViewById(R.id.ImageButton00);
Resources r = getResources();
Drawable[] layers = new Drawable[2];
layers[0] = r.getDrawable(R.drawable.image);
layers[1] = r.getDrawable(R.drawable.imagetwo);
LayerDrawable layerDrawable = new LayerDrawable(layers);
b0.setImageDrawable(layerDrawable);
他の回答を読んで、使用後に画像をリサイクルする必要があることがわかりました。これは最良の選択肢ですか?もしそうなら、LayerDrawable をビットマップに変換してリサイクルできるようにするにはどうすればよいですか?