在我的应用程序中,我有一个地图视图,它根据用户的方向旋转。为此,我将地图视图的大小设得非常大,超过了设备的宽度和高度。但是它在设备上运行得很完美,在模拟器上则会出现内存不足异常。我知道这是由于模拟器的堆内存较低引起的。
所有设备都具有更多的堆内存吗?还是有解决方案可以解决这个问题?
我的Locat输出:
我使用了旋转视图和扩展视图组的RotateView。
在RotateView的onMeasure方法中。
我的布局是:
所有设备都具有更多的堆内存吗?还是有解决方案可以解决这个问题?
我的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。
在RotateView的onMeasure方法中。
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>