我经历了很多与此错误相关的帖子,但没有为我的问题找到合适的解决方案。 在我的项目中有三个活动。每个活动中有4个动画我正在使用序列。在onclick上改变我的活动我得到vm预算内存错误。 如何在我们去其他活动的同时清除对活动的记忆?以便内存可以用于下一个活动.. 在此先感谢您的帮助...
发生错误如下....
09-10 10:35:12.046: ERROR/AndroidRuntime(472): FATAL EXCEPTION: main
09-10 10:35:12.046: ERROR/AndroidRuntime(472): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.graphics.Bitmap.nativeCreate(Native Method)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.content.res.Resources.loadDrawable(Resources.java:1709)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.content.res.Resources.getDrawable(Resources.java:581)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:265)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:788)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.content.res.Resources.loadDrawable(Resources.java:1694)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.content.res.Resources.getDrawable(Resources.java:581)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.view.View.setBackgroundResource(View.java:7393)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at com.bokstverna.InnerActivityR.onCreate(InnerActivityR.java:87)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.os.Looper.loop(Looper.java:123)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at java.lang.reflect.Method.invoke(Method.java:521)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-10 10:35:12.046: ERROR/AndroidRuntime(472): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:2)
你必须像下面那样缩放你的位图,
img.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 200,200, true));
然后它的大小不会超过。它将固定到特定的大小。