How to inflate a custom view inside a google map fragment?
To add images/points on map we can use Markers or GroundOverlay, but if we need a custom view (for example, a list or an image with buttons), both classes receive a BitmapDescriptor on their attributes .icon
and .image
, respectively, which turns a given layout into a plain image, losing its versatility, for example unable to add onClickListeners on buttons.
So is there a way to add a custom view inside google map fragment without it being transformed into an image?
Documentation clearly states that views will be rendered into images which annul any changes previously given to the view. Therefore there is no way to create a custom view with different behaviours inside google map.
Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (for example, after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.
From documentation: link