如何在Android上缩放标记,并正确设置阴影和onTap

时间:2009-11-17 20:30:10

标签: java android google-maps

我正在使用以下代码在MapView上缩放标记

OverlayItem oi = new OverlayItem(point,"Title", "Desc");
oi.setMarker(getCustomMarker(0.5f, 0.5f));
itemizedOverlay.addOverlay(oi);

private BitmapDrawable getCustomMarker(float scaleWidth, float scaleHeight){
    int width = originalMarker.getWidth();
    int height = originalMarker.getHeight();

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap bitmap = Bitmap.createBitmap(originalMarker, 0, 0, width, height, matrix, true);

    BitmapDrawable bm = new BitmapDrawable(bitmap);
    bm.setBounds(0,0,bitmap.getWidth(),bitmap.getHeight());

    return bm;
}

可以工作,但是缩放时标记下面的阴影有错误的偏移量。也;我覆盖ItemizedOverlay中的public boolean onTap(int index)以检测标记上的点击,但它似乎不准确。我可以点击标记之外的某个范围并仍然触发onTap ...

1 个答案:

答案 0 :(得分:1)

我用它来设置阴影

int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
drawable.setBounds(-w / 2, -h, w / 2, 0);