Multiple line or break line in .snippet (google maps apiv2)

ぃ、小莉子 提交于 2019-11-27 20:48:56
tony m

You need to use a custom InfoWindowAdapter to change the layout of InfoWindow to a custom design defined using a layout file. Basically you need to :

  1. Declare your function using GoogleMap.setInfoWindowAdapter(Yourcustominfowindowadpater)
  2. Have a class like below:

...

class Yourcustominfowindowadpater implements InfoWindowAdapter {
    private final View mymarkerview;

    Yourcustominfowindowadpater() {
        mymarkerview = getLayoutInflater()
            .inflate(R.layout.custominfowindow, null); 
    }

    public View getInfoWindow(Marker marker) {      
        render(marker, mymarkerview);
        return mymarkerview;
    }

    public View getInfoContents(Marker marker) {
       return null;
    }

    private void render(Marker marker, View view) {
       // Add the code to set the required values 
       // for each element in your custominfowindow layout file
    }
}

You will have to use InfoWindowAdapter to create custom info windows. The default implementation somehow removes newlines from snippet, which might be considered a minor bug.

I would like to add something to @tony , According to documentation you cant add action to your custom view as it draw as image in run time.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!