在我的应用程序中,我有根据用户方向旋转的地图视图。为此我将地图视图大小非常大,它跨越设备的宽度和高度。但它在设备中完美运行但在模拟器中显示内存异常。我知道这是因为模拟器的堆内存很少。
所有设备都有更多的堆内存。或者任何解决方案是他们解决这个问题吗?
我的Locat输出
07-05 12:32:49.982: E/AndroidRuntime(907): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
07-05 12:32:49.982: E/AndroidRuntime(907): at android.graphics.Bitmap.nativeCreate(Native Method)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
07-05 12:32:49.982: E/AndroidRuntime(907): at com.google.android.maps.StreetViewRenderer.generateNewTileImage(StreetViewRenderer.java:120)
07-05 12:32:49.982: E/AndroidRuntime(907): at com.google.android.maps.StreetViewRenderer.renderTile(StreetViewRenderer.java:88)
07-05 12:32:49.982: E/AndroidRuntime(907): at com.google.android.maps.AndroidTileOverlayRenderer.renderTile(AndroidTileOverlayRenderer.java:62)
07-05 12:32:49.982: E/AndroidRuntime(907): at com.google.googlenav.map.Map.drawTile(Unknown Source)
07-05 12:32:49.982: E/AndroidRuntime(907): at com.google.googlenav.map.Map.drawMapBackground(Unknown Source)
07-05 12:32:49.982: E/AndroidRuntime(907): at com.google.googlenav.map.Map.drawMap(Unknown Source)
07-05 12:32:49.982: E/AndroidRuntime(907): at com.google.android.maps.MapView.drawMap(MapView.java:1048)
07-05 12:32:49.982: E/AndroidRuntime(907): at com.google.android.maps.MapView.onDraw(MapView.java:486)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.View.draw(View.java:6740)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-05 12:32:49.982: E/AndroidRuntime(907): at com.trafficmate.utils.RotateView.dispatchDraw(RotateView.java:48)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.View.draw(View.java:6743)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.widget.FrameLayout.draw(FrameLayout.java:352)
07-05 12:32:49.982: E/AndroidRuntime(907): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1842)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewRoot.draw(ViewRoot.java:1407)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.os.Handler.dispatchMessage(Handler.java:99)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.os.Looper.loop(Looper.java:123)
07-05 12:32:49.982: E/AndroidRuntime(907): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-05 12:32:49.982: E/AndroidRuntime(907): at java.lang.reflect.Method.invokeNative(Native Method)
07-05 12:32:49.982: E/AndroidRuntime(907): at java.lang.reflect.Method.invoke(Method.java:521)
07-05 12:32:49.982: E/AndroidRuntime(907): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-05 12:32:49.982: E/AndroidRuntime(907): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-05 12:32:49.982: E/AndroidRuntime(907): at dalvik.system.NativeStart.main(Native Method)
我使用RotateView和Extenting View Group
on旋转视图的测量方法
private static final float SQ2 = 3.5f;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int w = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
int h = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
//int w=SonarView.display.getWidth();
//int h=SonarView.display.getHeight();
int sizeSpec;
if (w > h) {
sizeSpec = MeasureSpec.makeMeasureSpec((int) (w * SQ2), MeasureSpec.EXACTLY);
} else {
sizeSpec = MeasureSpec.makeMeasureSpec((int) (h * SQ2), MeasureSpec.EXACTLY);
}
final int count = getChildCount();
for (int i = 0; i < count; i++) {
getChildAt(i).measure(sizeSpec, sizeSpec);
}
Log.e("sizeSpec",""+sizeSpec);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
我的布局是
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<com.trafficmate.utils.RotateView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rview"
>
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:apiKey="0947Aqi7xG3QScZEvvOLtLJNtVss6PFjAquxZ2w"
android:clickable="true"
android:saveEnabled="true"
/>
</com.trafficmate.utils.RotateView>
</FrameLayout>
答案 0 :(得分:0)
您可以通过将 android:largeHeap =“true” 添加到您的Application标记来增加堆大小。模拟器对常规堆和大堆具有相同的堆大小,因此您必须在设备上进行检查。
通过ActivityManager.getLargeMemoryClass();
进行检查