2
是否可以重寫MyLocationOverlay()的onDraw方法,並用其他方法替換標準閃爍的藍色圖標。我可以實現這個的方式有哪些?動畫可繪製MyLocationOverlay()
是否可以重寫MyLocationOverlay()的onDraw方法,並用其他方法替換標準閃爍的藍色圖標。我可以實現這個的方式有哪些?動畫可繪製MyLocationOverlay()
真正好的答案,在這裏你的問題: myLocationOverlay change the marker
的drawMyLocation(..)
函數中繪製動畫GIF圖像。 Display Animated GIF
public class CurrentLocationOverlay extends MyLocationOverlay {
// TODO: use dynamic calculation?
private final static int PADDING_ACTIVE_ZOOM = 50;
private MapController mc;
private Bitmap marker;
private Point currentPoint = new Point();
private boolean centerOnCurrentLocation = true;
private int height;
private int width;
/**
* By default this CurrentLocationOverlay will center on the current location, if the currentLocation is near the
* edge, or off the screen. To dynamically enable/disable this, use {@link #setCenterOnCurrentLocation(boolean)}.
*
* @param context
* @param mapView
*/
public CurrentLocationOverlay(Context context, MapView mapView) {
super(context, mapView);
this.mc = mapView.getController();
this.marker = BitmapFactory.decodeResource(context.getResources(), R.drawable.position);
}
@Override
protected void drawMyLocation(Canvas canvas, MapView mapView, Location lastFix, GeoPoint myLocation, long when) {
// TODO: find a better way to get height/width once the mapView is layed out correctly
if (this.height == 0) {
this.height = mapView.getHeight();
this.width = mapView.getWidth();
}
mapView.getProjection().toPixels(myLocation, currentPoint);
canvas.drawBitmap(marker, currentPoint.x, currentPoint.y - 40, null);
}
@Override
public synchronized void onLocationChanged(Location location) {
super.onLocationChanged(location);
// only move to new position if enabled and we are in an border-area
if (mc != null && centerOnCurrentLocation && inZoomActiveArea(currentPoint)) {
mc.animateTo(getMyLocation());
}
}
private boolean inZoomActiveArea(Point currentPoint) {
if ((currentPoint.x > PADDING_ACTIVE_ZOOM && currentPoint.x < width - PADDING_ACTIVE_ZOOM)
&& (currentPoint.y > PADDING_ACTIVE_ZOOM && currentPoint.y < height - PADDING_ACTIVE_ZOOM)) {
return false;
}
return true;
}
public void setCenterOnCurrentLocation(boolean centerOnCurrentLocation) {
this.centerOnCurrentLocation = centerOnCurrentLocation;
}
}
這實際上是一種重寫位置可繪製標記的方法,但是問題的「Animate」部分呢?這裏閃爍的效果真的很有趣。 – Arnaud 2012-03-10 11:54:15
使用上面的代碼,並看看這個問題: http://stackoverflow.com/questions/3660209/android-display-animated-gif。 – Jack 2012-03-10 14:02:31