在 google 地图中扩充自定义视图

Inflate a custom View inside google map

如何在 google 地图片段中膨胀自定义视图?

要在地图上添加 images/points 我们可以使用标记或 GroundOverlay,但如果我们需要自定义视图(例如,列表或带按钮的图像),两者 类 都会收到一个 BitmapDescriptor分别在它们的属性 .icon.image 上,这会将给定的布局变成普通图像,从而失去其多功能性,例如无法在按钮上添加 onClickListeners。

那么有没有办法在 google 地图片段中添加自定义视图而不将其转换为图像?

文档明确指出视图将被渲染成图像,这会取消之前对视图所做的任何更改。因此无法在 google 地图中创建具有不同行为的自定义视图。

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.

来自文档:link