我已經搜索了很多關於我的上下按鈕的解決方案,似乎無法獲得任何工作。在程序中使用ImageButton時,我能夠在出現OutOfMemoryError之前按下三個ImageButton。請任何幫助將是偉大的。內存不足 - 位圖大小超出虛擬機預算
for(int i = 0; i < keys.length; i++)
{
keys[i].setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
for(int down = 0; down < keys.lenght; down++)
{
if(v == keys[down])
{
keys[down].keys[down].setImageResource(drawIDDOWN[down]);
keys[down].setAdjustViewBounds(true);
}
}
}
if(event.getAction() == MotionEvent.ACTION_UP)
{
for(int up = 0; up < keys.length; up++)
{
if(v == keys[up])
{
keys[up].setImageResource(drawIDUP[up]);
keys[up].setAdjustViewBounds(true);
}
}
}
return false;
}
});
}
這裏是logcat的:
threadid=1: thread exiting with uncaught exception
FATAL EXCEPTION: main
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
android.graphics.Bitmap.nativeCreate(Native Method)
android.graphics.Bitmap.createBitmap(Bitmap.java:477)
android.graphics.Bitmap.createBitmap(Bitmap.java:444)
android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498)
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473)
android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
android.content.res.Resources.loadDrawable(Resources.java:1709)
android.content.res.Resources.getDrawable(Resources.java:581)
android.widget.ImageView.resolveUri(ImageView.java:501)
android.widget.ImageView.setImageResource(ImageView.java:280)
f7kidzCalc.com.KidzCalcActivity$1.onTouch(KidzCalcActivity.java:253)
android.view.View.dispatchTouchEvent(View.java:3881)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent
(PhoneWindow.java:1691)
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent
(PhoneWindow.java:1125)
android.app.Activity.dispatchTouchEvent(Activity.java:2096)
com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent
(PhoneWindow.java:1675)
android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:123)
android.app.ActivityThread.main(ActivityThread.java:3683)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:507)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
dalvik.system.NativeStart.main(Native Method)
有一種簡單的方法來收集垃圾,回收的圖像或只是什麼?我被卡住了。
圖像的大小是多少? – 2012-03-16 23:07:46
每個ImageButton約有60kb – abotrix 2012-03-16 23:11:28
嘗試在主類中實現OnTouchListener方法,而不是使用內聯類實例。儘管我懷疑這會有所幫助。 – akonsu 2012-03-16 23:31:40