开发者

How to scale markers on Android, and set shadow and onTap correctly

I'm scaling markers on a MapView with the following code

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

and:

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.ge开发者_如何学CtHeight());

    return bm;
}

which works, but the shadow below the marker has wrong offset when scaled. Also; i override the public boolean onTap(int index) in ItemizedOverlay to detect taps on the markers, but it seems inaccurate. I can click some range outside the marker and still trigger onTap...


I use this to set the shadow

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜