Android OverlayItem.setMarker(): 更改单个项目的标记

8
尝试更改覆盖物项的标记时,我注意到setMarker()会使该项不可见。下面是代码示例。
//Create new marker
Drawable icon = this.getResources().getDrawable(R.drawable.marker);

//Set the new marker to the overlay
overlayItem.setMarker(icon);

你找到解决方案了吗?我也遇到了同样的问题。使用特定的drawable调用setMarker()会使图标不可见... - MobileCushion
1
您需要使用 setBounds() 指定边界矩形。 - slybloty
1
确实有效,你应该回答这个问题 ;) - MobileCushion
2个回答

11
需要为Drawable指定一个边界矩形:
//Create new marker
Drawable icon = this.getResources().getDrawable(R.drawable.marker);

//Set the bounding for the drawable
icon.setBounds(
    0 - icon.getIntrinsicWidth() / 2, 0 - icon.getIntrinsicHeight(), 
    icon.getIntrinsicWidth() / 2, 0);

//Set the new marker to the overlay
overlayItem.setMarker(icon);

0
我相信这会起作用:
public void addOverlay(final OverlayItem overlay)
    {
        creditOverlay.add(overlay);
        populate();
        boundCenter(customMarker);
    }

你需要在添加地图覆盖物时调用boundCenterboundCenterBottom。在SetMarker()中,只需设置自定义标记即可。

这将导致所有的项目使用相同的标记,除非将方法更改为:addOverlay(OverlayItem, Drawable) - slybloty

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接