私のアプリケーションでは、ユーザーの方向に基づいて回転するマップ ビューがあります。このため、デバイスの幅と高さと交差するマップ ビューのサイズを非常に大きくしました。しかし、デバイスでは完全に機能しますが、エミュレータではメモリ不足の例外が表示されます。エミュレータのヒープメモリが少ないためです。
すべてのデバイスがより多くのヒープメモリを持っていますか?それとも、これを解決するための解決策はありますか?
My 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)
Extenting View Group で RotateView を使用しました
Rotate View の 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>