Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was trying to do something similar - draw Google Maps style balloons with custom views inside them onto the map. I tried overriding the draw() of an OverlayItem, and drawing the layout I'd defined in XML that way. The problem was in coverting the View to a Drawable to draw onto the MapView canvas meant I lost all event handling capabilities of the Layout so things like buttons etc. did not work properly. If you don't have any events on the images to worry about then this could work, you'll just need to inflate your view using the current Activity's LayoutInflater (activity.getLayoutInflater()), measure and lay it out as described under the 'How Android Draws Views' page on the android developers site (couldn't post a link due to new user restrictions, sorry!), and finally call buildDrawingCache() and getDrawingCache() on your View to get it as a Bitmap. This can then be drawn onto the Canvas passed the draw() method of a subclass of Overlay that you've built.</p> <p>I actually went for the second approach you suggested (adding each one as a child view to MapView, using MapView.LayoutParams to hover the layout over the OverlayItem in question) in the end. I only had one child view to worry about though so I wasn't too worried about the efficiency here, it might be more of a problem to you if that is actually something to be concerned about (it might be worth testing first though). There's a small writeup of what I did <a href="http://www.actionshrimp.com/2011/05/speech-bubble-popups-containing-a-view-for-android-mapview/" rel="nofollow">here</a> with a bit more detail.</p> <p>Finally you might want to look at <a href="https://github.com/jgilfelt/android-mapviewballoons" rel="nofollow">android-mapviewballoons</a>'s approach to this, which is well worth a look.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload