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

sly*_*oty 8 java android android-maps

尝试从叠加项目更改标记我注意到setMarker()使项目不可见.这是代码示例.

//Create new marker
Drawable icon = this.getResources().getDrawable(R.drawable.marker);

//Set the new marker to the overlay
overlayItem.setMarker(icon);
Run Code Online (Sandbox Code Playgroud)

sly*_*oty 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);
Run Code Online (Sandbox Code Playgroud)