我在mapview上绘制了一些标记(来自一个drawable),但我想在每个标记上显示不同的数字。
数字存储在数组中。我创建了一个函数来在drawable上面写文本,这就是我所做的:
List<Overlay> mapOverlays = mapView.getOverlays();
GeoPoint geoPoint = null;
Drawable marker;
int size = addresses.length;
marker = writeOnDrawable(R.drawable.marker, "10");//my number to write here
itemizedOverlay = new ItemizedOverlay(marker, mapView);
for(int i = 0; i < size; i++) {
geoPoint = new GeoPoint((int) (latitudes[i] * 1E6), (int) (longitudes[i] * 1E6));
itemizedOverlay.addOverlay(new OverlayItem(geoPoint, addresses[i], ""));
}
mapOverlays.add(itemizedOverlay);
但是,在这段代码中,我为所有标记显示相同的数字,我想使用我的数字数组为每个标记显示不同的数字。
这是否意味着我必须使用尽可能多的ItemizedOverlay,因为我有数字? 或者您有什么建议吗?
答案 0 :(得分:0)
我终于通过使用几个ItemizedOverlay来实现它。 我把它放在for循环的开头:
itemizedOverlay = new ItemizedOverlay(marker, mapView);
以及最后:
mapOverlays.add(itemizedOverlay);
我的设备(GN)上的一切正常,直到我在我得到它的VM上测试它:
09-02 09:36:56.335: E/dalvikvm-heap(231): 20424-byte external allocation too large for this process.
09-02 09:36:56.335: E/(231): VM won't let us allocate 20424 bytes
09-02 09:36:56.335: W/dalvikvm(231): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
09-02 09:36:56.335: E/AndroidRuntime(231): Uncaught handler: thread main exiting due to uncaught exception
09-02 09:36:56.386: E/AndroidRuntime(231): android.view.InflateException: Binary XML file line #2: Error inflating class java.lang.reflect.Constructor
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.LayoutInflater.createView(LayoutInflater.java:512)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.readystatesoftware.mapviewballoons.BalloonOverlayView.setupView(BalloonOverlayView.java:79)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.readystatesoftware.mapviewballoons.BalloonOverlayView.<init>(BalloonOverlayView.java:58)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay.createBalloonOverlayView(BalloonItemizedOverlay.java:151)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay.createAndDisplayBalloonOverlay(BalloonItemizedOverlay.java:284)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay.onTap(BalloonItemizedOverlay.java:126)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:346)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.GestureDetector.onTouchEvent(GestureDetector.java:506)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.google.android.maps.MapView.onTouchEvent(MapView.java:628)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.readystatesoftware.maps.TapControlledMapView.onTouchEvent(TapControlledMapView.java:62)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.View.dispatchTouchEvent(View.java:3672)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:850)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1712)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.app.Activity.dispatchTouchEvent(Activity.java:1987)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1696)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.os.Looper.loop(Looper.java:123)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.app.ActivityThread.main(ActivityThread.java:4203)
09-02 09:36:56.386: E/AndroidRuntime(231): at java.lang.reflect.Method.invokeNative(Native Method)
09-02 09:36:56.386: E/AndroidRuntime(231): at java.lang.reflect.Method.invoke(Method.java:521)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
09-02 09:36:56.386: E/AndroidRuntime(231): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
09-02 09:36:56.386: E/AndroidRuntime(231): at dalvik.system.NativeStart.main(Native Method)
09-02 09:36:56.386: E/AndroidRuntime(231): Caused by: java.lang.reflect.InvocationTargetException
09-02 09:36:56.386: E/AndroidRuntime(231): at android.widget.LinearLayout.<init>(LinearLayout.java:92)
09-02 09:36:56.386: E/AndroidRuntime(231): at java.lang.reflect.Constructor.constructNative(Native Method)
09-02 09:36:56.386: E/AndroidRuntime(231): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view.LayoutInflater.createView(LayoutInflater.java:499)
09-02 09:36:56.386: E/AndroidRuntime(231): ... 35 more
09-02 09:36:56.386: E/AndroidRuntime(231): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:439)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:322)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:688)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.content.res.Resources.loadDrawable(Resources.java:1710)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.content.res.Resources.getDrawable(Resources.java:585)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:146)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:779)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:720)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.content.res.Resources.loadDrawable(Resources.java:1695)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
09-02 09:36:56.386: E/AndroidRuntime(231): at android.view
正如我所担心的那样,需要大量的记忆......有没有办法避免这种情况? 你认为这也会发生在低内存设备上吗?