我想知道在视图中使用图像可绘制对象时如何将它们加载到内存中。
我的问题是我有一个大尺寸的图像(大约 600x700),它的重量只有 4kb。我认为没有必要创建一个 9-patch 图像,因为图像足够小。但是,当我尝试将此图像用作背景时,Android 出现内存不足错误。
06-28 14:54:09.359: E/dalvikvm-heap(2272): Out of memory on a 6816336-byte allocation.
06-28 14:54:09.359: I/dalvikvm(2272): "main" prio=5 tid=1 RUNNABLE
06-28 14:54:09.359: I/dalvikvm(2272): | group="main" sCount=0 dsCount=0 obj=0x40a5d460 self=0x12828
06-28 14:54:09.359: I/dalvikvm(2272): | sysTid=2272 nice=0 sched=0/0 cgrp=default handle=1074603144
06-28 14:54:09.359: I/dalvikvm(2272): | schedstat=( 0 0 0 ) utm=162 stm=18 core=0
06-28 14:54:09.359: I/dalvikvm(2272): at android.graphics.Bitmap.nativeCreate(Native Method)
06-28 14:54:09.359: I/dalvikvm(2272): at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
06-28 14:54:09.359: I/dalvikvm(2272): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
06-28 14:54:09.359: I/dalvikvm(2272): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
06-28 14:54:09.359: I/dalvikvm(2272): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
06-28 14:54:09.359: I/dalvikvm(2272): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
06-28 14:54:09.359: I/dalvikvm(2272): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
06-28 14:54:09.359: I/dalvikvm(2272): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
06-28 14:54:09.359: I/dalvikvm(2272): at android.content.res.Resources.loadDrawable(Resources.java:1937)
06-28 14:54:09.359: I/dalvikvm(2272): at android.content.res.Resources.getDrawable(Resources.java:664)
06-28 14:54:09.359: I/dalvikvm(2272): at android.view.View.setBackgroundResource(View.java:11588)
06-28 14:54:09.359: I/dalvikvm(2272): at com.telcel.olmpiadas2012.gui.viewcontrollers.medals.MedalsDetail.<init>(MedalsDetail.java:14)
06-28 14:54:09.359: I/dalvikvm(2272): at com.telcel.olmpiadas2012.gui.viewcontrollers.medals.MedalsHomeVC.onCreate(MedalsHomeVC.java:53)
06-28 14:54:09.359: I/dalvikvm(2272): at android.app.Activity.performCreate(Activity.java:4465)
06-28 14:54:09.359: I/dalvikvm(2272): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-28 14:54:09.367: I/dalvikvm(2272): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
06-28 14:54:09.367: I/dalvikvm(2272): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
06-28 14:54:09.367: I/dalvikvm(2272): at android.app.ActivityThread.access$600(ActivityThread.java:122)
06-28 14:54:09.367: I/dalvikvm(2272): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
06-28 14:54:09.367: I/dalvikvm(2272): at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 14:54:09.367: I/dalvikvm(2272): at android.os.Looper.loop(Looper.java:137)
06-28 14:54:09.367: I/dalvikvm(2272): at android.app.ActivityThread.main(ActivityThread.java:4340)
06-28 14:54:09.367: I/dalvikvm(2272): at java.lang.reflect.Method.invokeNative(Native Method)
06-28 14:54:09.367: I/dalvikvm(2272): at java.lang.reflect.Method.invoke(Method.java:511)
06-28 14:54:09.367: I/dalvikvm(2272): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-28 14:54:09.367: I/dalvikvm(2272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-28 14:54:09.367: I/dalvikvm(2272): at dalvik.system.NativeStart.main(Native Method)
我已经毫无问题地添加了其他大图像作为背景,我怀疑我的应用程序占用了除了 4kb 之外的所有内存空间,因为其他活动加载的资源比这个更多,而且我访问它们没有问题。
我应该考虑其他方面而不是最终图像字节大小吗?