我在我的 Android 应用程序中有一个带有 a MapView
in a的布局ViewSwitcher
(它是在 a 中RelativeLayout
,而不是整个屏幕)。
我的问题是点击该项目非常慢,点击几下后它会触发java.lang.OutOfMemoryError
(在设备和模拟器上)。
07-19 15:39:29.839: E/dalvikvm-heap(14832): 86400-byte external allocation too large for this process.
07-19 15:39:29.839: E/GraphicsJNI(14832): VM won't let us allocate 86400 bytes
07-19 15:39:29.889: I/dalvikvm-heap(14832): Clamp target GC heap from 32.934MB to 32.000MB
07-19 15:39:29.889: D/dalvikvm(14832): GC_FOR_MALLOC freed <1K, 29% free 8447K/11847K, external 20846K/21207K, paused 47ms
07-19 15:39:29.889: D/skia(14832): --- decoder->decode returned false
07-19 15:39:29.889: D/AndroidRuntime(14832): Shutting down VM
07-19 15:39:29.889: W/dalvikvm(14832): threadid=1: thread exiting with uncaught exception (group=0x2aac8578)
07-19 15:39:29.889: E/AndroidRuntime(14832): FATAL EXCEPTION: main
07-19 15:39:29.889: E/AndroidRuntime(14832): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:504)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:370)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:715)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.graphics.drawable.Drawable.createFromStream(Drawable.java:675)
07-19 15:39:29.889: E/AndroidRuntime(14832): at mypackage.widgets.LocalisationArrayAdapter.getView(LocalisationArrayAdapter.java:92)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.widget.AbsListView.obtainView(AbsListView.java:1498)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.widget.ListView.measureHeightOfChildren(ListView.java:1220)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.widget.ListView.onMeasure(ListView.java:1131)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.view.View.measure(View.java:8462)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3231)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.widget.FrameLayout.onMeasure(FrameLayout.java:254)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.view.View.measure(View.java:8462)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:566)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:381)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.view.View.measure(View.java:8462)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3231)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.widget.FrameLayout.onMeasure(FrameLayout.java:254)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.view.View.measure(View.java:8462)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.widget.LinearLayout.measureVertical(LinearLayout.java:535)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.widget.LinearLayout.onMeasure(LinearLayout.java:313)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.view.View.measure(View.java:8462)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3231)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.widget.FrameLayout.onMeasure(FrameLayout.java:254)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.view.View.measure(View.java:8462)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.view.ViewRoot.performTraversals(ViewRoot.java:861)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.view.ViewRoot.handleMessage(ViewRoot.java:1882)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.os.Handler.dispatchMessage(Handler.java:99)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.os.Looper.loop(Looper.java:130)
07-19 15:39:29.889: E/AndroidRuntime(14832): at android.app.ActivityThread.main(ActivityThread.java:3701)
07-19 15:39:29.889: E/AndroidRuntime(14832): at java.lang.reflect.Method.invokeNative(Native Method)
07-19 15:39:29.889: E/AndroidRuntime(14832): at java.lang.reflect.Method.invoke(Method.java:507)
07-19 15:39:29.889: E/AndroidRuntime(14832): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
07-19 15:39:29.889: E/AndroidRuntime(14832): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
07-19 15:39:29.889: E/AndroidRuntime(14832): at dalvik.system.NativeStart.main(Native Method)
所以我的问题是:真正导致此错误的原因是什么?
这不是全屏
MapView
吗?我遵循了这篇文章的解决方案:android MapView 总是在嵌套元素中导致 OutOfMemoryError但它没有做任何事情。
是因为
ViewSwitcher
theMapView
和它的另一个孩子 (aListView
) 都在内存中吗?如果是这样,我怎样才能让android重绘每个视图
showNext()
?
当我有两个不同的活动而不是ViewSwitcher
,并且当MapView
整个布局运行良好时,它是什么问题,我该如何改变它?