2010-04-15 7 views
2

내 액티비티의 oncreate 메소드에서 단계별로 Google MapView를 확대하려고합니다. 매번 내가 IllegalArgumentException를 얻을 mapController를 통해지도를 확대하려고 : 나는 MapController의 zoomOut 또는 zoomIn 함수를 호출하는 경우IllegalArgumentException : Google MapView의 zoomOut 중에 너비와 높이가> 0이어야합니다.

04-15 10:16:51.012: ERROR/AndroidRuntime(528): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.client/android.client.ui.showstores.StoreMap}: java.lang.IllegalArgumentException: width and height must be > 0 

이 예외가 슬로우됩니다. 슬프게도 내가 사용하고있는 zoomIn 함수는 인수를 취하지 않습니다. 내가 줌 함수를 호출하고있어

onCreateMethod은 다음과 같습니다 : 나는 특별한 아무것도하지 않고있어 때문에

mapView = (MapView) findViewById(R.id.map); 
    mapView.setBuiltInZoomControls(true); 
    MapController mapController = mapView.getController(); 
    mapController.zoomIn(); 

내가 여기 손실에 조금 해요.

전체 스택 트레이스는 다음과 같습니다

04-15 10:16:51.012: ERROR/AndroidRuntime(528): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.client/android.client.ui.showstores.StoreMap}: java.lang.IllegalArgumentException: width and height must be > 0 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at android.app.ActivityThread.access$2100(ActivityThread.java:116) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at android.os.Handler.dispatchMessage(Handler.java:99) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at android.os.Looper.loop(Looper.java:123) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at android.app.ActivityThread.main(ActivityThread.java:4203) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at java.lang.reflect.Method.invokeNative(Native Method) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at java.lang.reflect.Method.invoke(Method.java:521) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at dalvik.system.NativeStart.main(Native Method) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528): Caused by: java.lang.IllegalArgumentException: width and height must be > 0 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at android.graphics.Bitmap.nativeCreate(Native Method) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at android.graphics.Bitmap.createBitmap(Bitmap.java:468) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at com.google.android.maps.ZoomHelper.createSnapshot(ZoomHelper.java:305) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at com.google.android.maps.ZoomHelper.doZoom(ZoomHelper.java:137) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at com.google.android.maps.ZoomHelper.doZoom(ZoomHelper.java:126) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at com.google.android.maps.MapView.doZoom(MapView.java:1459) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at com.google.android.maps.MapView.doZoom(MapView.java:1468) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at com.google.android.maps.MapController.zoomIn(MapController.java:427) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at android.client.ui.showstores.StoreMap.onCreate(StoreMap.java:58) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364) 
04-15 10:16:51.012: ERROR/AndroidRuntime(528):  ... 11 more 

답변

2

안드로이드는 나중에까지 뷰의 폭과 높이를 설정하지 않습니다, 그래서에서 onCreate에 0을 수 있습니다. 뷰는 "onLayoutChanged"또는 이와 유사한 메서드에서 크기를 지정한다고 생각합니다. 어쩌면 오버 라이드하고 줌을 수행 할 수 있습니다.

2

onCreate 또는 onResume 대신 onWindowFocusChanged (부울 hasFocus)에서 확대/축소 메서드를 호출 할 수 있습니다.

3

해당 상황에 대한 해결책을 찾았습니다.

int zoomSteps = 2; 

    int currentLatitudeSpan = mMapView.getLatitudeSpan(); 
    int currentLongitudeSpan = mMapView.getLongitudeSpan(); 

    int zoomedLatitudeSpan = 2 * zoomSteps * currentLatitudeSpan; 
    int zoomedLongitudeSpan = 2 * zoomSteps * currentLongitudeSpan; 

    mMapController.zoomToSpan(zoomedLatitudeSpan, zoomedLongitudeSpan);' 

이 조각은 두 번

지도를 확대