EDIT: It seems like ItemizedOverlay.setFocus(item)
is the way to get a single item to be drawn on top (after a mapview.invalidate()
). I can't get it to work the way I want it, because when the mapview
animates it removes the focus and drawing order changes back.
Many thanks to Android Mapview: Control ordering of multiple types of OverlayItems? for pointing the drawing order behavior out to me.
For right now this is my heavy-handed solution. You can take complete control over the order in which the OverlayItem
s are shown by overriding getIndexToDraw
in ItemizedOverlay
.
protected int getIndexToDraw(final int drawingOrder)
The drawingOrder
parameter is the same index as the parameter passed into createItem
. You return the order in which the markers will be drawn (higher numbers are drawn later which means "on top").
In my particular case, I have an ArrayList
of items that I sort and make sure the selected OverlayItem
is always last in the list. Then my getIndexToDraw
method looks like this:
@Override
protected int getIndexToDraw(final int drawingOrder)
{
return drawingOrder;
}
In order to draw the OverlayItems
in the same order as I have them stored in my ArrayList
.