我在這裏分享我的源
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
try {
for (int i = 0; i < size(); i++) {
OverlayItem item = getItem(i);
String driverName = item.getSnippet();
Data.activlyShownDrivers.add(driverName);
Point screenPts = new Point();
mapView.getProjection().toPixels(item.getPoint(), screenPts);
Bitmap bmp = null;
Context ctx = ShowAll.getContext();
long angle = (long) Double.parseDouble(item.getTitle());
// ---add the marker---
bmp = BitmapFactory.decodeResource(ctx.getResources(),
R.drawable.img1);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setStyle(Style.FILL_AND_STROKE);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y, null);
canvas.drawText(driverName, screenPts.x, screenPts.y, paint);
}
// }
} catch (Exception e) {
try {
Log.e(Data.LOG, e.getMessage());
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
ok..in ur代碼是在繪製方法中添加圖像。但我將這些圖像添加到overlayItem列表中。此列表添加到具有draw()方法作爲其方法之一的類的構造函數中......可以提供與此相關的解決方案嗎?由於要添加的疊加圖像很多,最好將它們添加到其構造函數的疊加項列表中。如果我不想將我的所有圖像從構造函數移動到我的繪製方法中,那將是非常棒的。 – Urban 2011-03-02 13:52:36
可以回答並解釋你的代碼。使用draw()之前,你是否填充()你覆蓋?如果你已經有你的覆蓋物,那麼什麼是img1? PLZ需要幫助。 – Urban 2011-03-03 10:10:29