我永遠無法讓它工作多次。我最終添加了一個無所作爲的疊加層,並在覆蓋層中放置了一個onTouchEvent()。這個工作
public class OsmdroidDemoMap extends Activity {
private MapView mMapView;
private MapController mMapController;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.osm_main);
mMapView = (MapView) findViewById(R.id.mapview);
mMapView.setTileSource(TileSourceFactory.MAPNIK);
mMapView.setBuiltInZoomControls(true);
mMapView.setMultiTouchControls(true);
mMapController = mMapView.getController();
mMapController.setZoom(13);
GeoPoint gPt = new GeoPoint(51500000, -150000);
mMapController.setCenter(gPt);
MapOverlay movl = new MapOverlay(this);
mMapView.getOverlays().add(movl);
}
public class MapOverlay extends org.osmdroid.views.overlay.Overlay {
public MapOverlay(Context ctx) {super(ctx);}
@Override
protected void draw(Canvas c, MapView osmv, boolean shadow) { }
@Override
public boolean onTouchEvent(MotionEvent e, MapView mapView) {
if(e.getAction() == MotionEvent.ACTION_DOWN)
Toast.makeText(OsmdroidDemoMap.this, "Touched", Toast.LENGTH_SHORT).show();
return false;
}
}
}
是的,我沒試過,但它並沒有奏效。 – fulupr 2012-02-23 21:00:22
嗡嗡聲。也許你可以嘗試onTouchEvent?您可以在MapActivity中重寫此方法 – 2012-02-23 21:02:44
我不能@Override onTouchEvent方法,因爲活動只是擴展了Activity,因此它給我一個錯誤,指出「MainActivity類型的onTouchEvent(MotionEvent,MapView)方法必須重寫超類方法」。 – fulupr 2012-02-23 21:09:13