2012-09-11 51 views
0

我想爲MyLocationOverlay的自定義標記添加陰影。我試過這個使用this questionAndroid - 如何在自定義MyLocationOverlay中添加陰影

@Override 
    protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) { 
    mapView.getProjection().toPixels(myLocation, currentPoint); 
    canvas.drawBitmap(markerBitmap, currentPoint.x - this.markerBitmap.getWidth()/2, currentPoint.y - this.markerBitmap.getHeight(), null); 
    } 

    @Override 
    public synchronized boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { 

     if (getLastFix() == null) { 
     return super.draw(canvas, mapView, shadow, when); 
     } 

     if (markerDrawable != null) { 
      GeoPoint lastFixGeoPoint = new GeoPoint((int)(getLastFix().getLatitude() * 1E6), (int)(getLastFix().getLongitude() * 1E6)); 
      mapView.getProjection().toPixels(lastFixGeoPoint, currentPoint); 

      drawAt(canvas, markerDrawable, currentPoint.x, currentPoint.y, shadow); 
    } else if (getMyLocation() != null) { 
     drawMyLocation(canvas, mapView, getLastFix(), getMyLocation(), when); 
    } 
     return super.draw(canvas, mapView, shadow, when); 
} 

我在想什麼? 在此先感謝。

回答

0

最後,我可以畫一個陰影,爲MyLocationOverlay自定義標記,用下面的:

@Override 
protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) { 
    mapView.getProjection().toPixels(myLocation, currentPoint); 

    canvas.drawBitmap(shadowBitmap, currentPoint.x - this.markerBitmap.getWidth()/2, currentPoint.y - this.markerBitmap.getHeight(), null); 
    canvas.drawBitmap(markerBitmap, currentPoint.x - this.markerBitmap.getWidth()/2, currentPoint.y - this.markerBitmap.getHeight(), null); 
} 

我希望這可以幫助別人。