Android Png叠加问题

时间:2012-09-27 19:58:58

标签: android google-maps png overlay

public PNGOverlay(Bitmap original, GeoPoint topLeftGeoPoint, GeoPoint bottomRightGeoPoint) {
    this.original = Bitmap.createScaledBitmap(original, original.getWidth(), original.getHeight(), true);


    ...
    topGeoPoint = topLeftGeoPoint;
    bottomGeoPoint = bottomRightGeoPoint;
}

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        super.draw(canvas, mapView, false);

        Projection projection = mapView.getProjection();

        Point leftTop = new Point();
        Point rightTop = new Point();
        Point rightBottom = new Point();
        Point leftBottom = new Point();

        projection.toPixels(topGeoPoint, leftTop);
        projection.toPixels(new GeoPoint(topGeoPoint.getLatitudeE6(), bottomGeoPoint.getLongitudeE6()), rightTop);
        projection.toPixels(bottomGeoPoint, rightBottom);
        projection.toPixels(new GeoPoint(bottomGeoPoint.getLatitudeE6(), topGeoPoint.getLongitudeE6()), leftBottom);

        ....

        Paint paint = new Paint();
        paint.setFilterBitmap(true);
        paint.setAntiAlias(true);

        canvas.drawBitmap(original, null, new Rect(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y), paint);

       ....
}

我的代码有问题。当我在mapView上绘制png时,png图像显示在指南针上方和GPS位置指示器上?任何的想法?

1 个答案:

答案 0 :(得分:1)

从你的问题很难猜出你的问题到底是什么,但如果你的意思是PNG正在被其他叠加层绘制而你希望它在它们之下,你可以通过首先添加PNG叠加来解决它mapview。

MapView按照添加顺序从每个叠加层调用draw方法:

mapview.getoverlays().add(overlay1);
mapview.getoverlays().add(overlay2);

这会导致overlay2被覆盖在overlay1上。

mapview.getoverlays().add(overlay2);
mapview.getoverlays().add(overlay1);

这会导致overlay1被覆盖在overlay2上。

祝你好运。