在Android中将图片添加到Google地图标记标题

时间:2015-05-09 09:50:19

标签: android google-maps google-maps-markers

我不想更改标记的图像 我只想在标题中添加一个图像,以便它看起来不错

像这样的“阅读更多”图片..

enter image description here

有没有办法呢

感谢

1 个答案:

答案 0 :(得分:1)

标题称为InfoWindow。要实现自定义窗口,您需要:

1)创建实现GoogleMap.InfoWindowAdapter接口的类。像这样的东西(在这种情况下只是TextView):

public class MapItemAdapter implements GoogleMap.InfoWindowAdapter {

  TextView tv;

  public MapItemAdapter(Context context) {
      tv = new TextView(context);
      LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
      tv.setLayoutParams(lp);
      tv.setGravity(Gravity.CENTER);
  }


  @Override
  public View getInfoWindow(Marker marker) {
      tv.setText(marker.getTitle());
      return tv;
  }

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

2)将适配器设置为您在GoogleMap回调中收到的onMapReady()

@Override
public void onMapReady(final GoogleMap map) {
    ...
    map.setInfoWindowAdapter(new MapItemAdapter(this));
    ...
}