我正在开发一个有大约 15 个屏幕的 android 游戏应用程序。当我连续玩的时候,我随机出现内存不足的错误问题,有时在第15屏,有时在第12屏左右。
另外,请查看下面的 xml,其中一个屏幕。
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/MainFrame"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@+id/mainlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/woodenbg1" >
<Chronometer
android:id="@+id/chronometer"
android:layout_width="0dp"
android:layout_height="0dp"
android:textSize="20sp"
android:textStyle="bold"
android:typeface="sans"
android:visibility="gone" />
<ImageView
android:id="@+id/imageline"
android:layout_width="10000dp"
android:layout_height="wrap_content"
android:layout_marginTop="105dp"
android:src="@drawable/lineblackfornormal" />
<ImageView
android:id="@+id/imageviewunderalphac"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="350dp"
android:src="@drawable/whitec" />
<ImageView
android:id="@+id/backgroundofalphab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:src="@drawable/backgroundfordragimages"
android:visibility="invisible" />
<ImageView
android:id="@+id/backgroundofalphaa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="35dp"
android:src="@drawable/backgroundfordragimages"
android:visibility="invisible" />
<ImageView
android:id="@+id/backgroundofalphac"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="33dp"
android:src="@drawable/backgroundfordragimages"
android:visibility="invisible" />
<ImageView
android:id="@+id/imageviewunderleftalphab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="250dp"
android:layout_marginLeft="15dp"
android:src="@drawable/whiteb" />
<ImageView
android:id="@+id/imageviewunderrightalphaa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="250dp"
android:layout_marginRight="10dp"
android:src="@drawable/whitea" />
<ImageView
android:id="@+id/imageviewabovealphab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:src="@drawable/colouredb" />
<ImageView
android:id="@+id/imageviewabovealphaa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="35dp"
android:src="@drawable/coloureda" />
<ImageView
android:id="@+id/imageviewabovealphac"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/backgroundofalphac"
android:layout_marginTop="33dp"
android:src="@drawable/colouredc" />
</RelativeLayout>
</FrameLayout>
日志猫
05-16 12:22:18.989: E/GraphicsJNI(6745): VM won't let us allocate 2225664 bytes
05-16 12:22:18.999: E/AndroidRuntime(6745): FATAL EXCEPTION: main
05-16 12:22:18.999: E/AndroidRuntime(6745): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.graphics.Bitmap.nativeCreate(Native Method)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.content.res.Resources.loadDrawable(Resources.java:1709)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.content.res.Resources.getDrawable(Resources.java:581)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.view.View.setBackgroundResource(View.java:7533)
05-16 12:22:18.999: E/AndroidRuntime(6745): at com.ssn.myapp.NumbersLevel3.onCreate(NumbersLevel3.java:173)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2832)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.app.ActivityThread.access$1600(ActivityThread.java:117)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.os.Looper.loop(Looper.java:130)
05-16 12:22:18.999: E/AndroidRuntime(6745): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-16 12:22:18.999: E/AndroidRuntime(6745): at java.lang.reflect.Method.invokeNative(Native Method)
05-16 12:22:18.999: E/AndroidRuntime(6745): at java.lang.reflect.Method.invoke(Method.java:507)
05-16 12:22:18.999: E/AndroidRuntime(6745): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-16 12:22:18.999: E/AndroidRuntime(6745): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-16 12:22:18.999: E/AndroidRuntime(6745): at dalvik.system.NativeStart.main(Native Method)