要显示一个自定义布局在百度地图上面:
方法一:
1.生成view
mOverlayView = LayoutInflater.from(this).inflate(R.layout.overlay_map, null);
2,设置控件点击事件:
MQuery mmq = new MQuery(mOverlayView);
mmq.id(R.id.name).text(chooiceVo.getName());
if (headcache==null) {
mmq.id(R.id.img).image(R.drawable.header_baby);
} else {
mmq.id(R.id.img).image(headcache);
}
mmq.id(R.id.img).clicked(new OnClickListener() {
@Override
public void onClick(View arg0) {
LogUtil.showlog("imgview click");
WindowsUtil.getInstance().goPersonalInformationActivity(HomeActivity.this, chooiceVo);
}
});
//点击原点隐藏infowindow
mmq.id(R.id.img_point).clicked(new OnClickListener() {
@Override
public void onClick(View arg0) {
LogUtil.showlog("point click");
mBaiduMap.hideInfoWindow();
}
});
//点击地图隐藏infowindow
mBaiduMap.setOnMapClickListener(new OnMapClickListener() {
@Override
public boolean onMapPoiClick(MapPoi arg0) {
LogUtil.showlog("onMapPoiClick");
return false;
}
@Override
public void onMapClick(LatLng arg0) {
LogUtil.showlog("onMapClick");
mBaiduMap.hideInfoWindow();
}
});
3.显示出来:
mInfoWindow = new InfoWindow(mOverlayView, ll, 0);
mBaiduMap.showInfoWindow(mInfoWindow);
方法二:
1.生成view后生成bitmap:
bitmap = BitmapDescriptorFactory.fromView(mOverlayView);
2,点击事件,点击的是整个mark
// OnInfoWindowClickListener listener = new OnInfoWindowClickListener() {
// @Override
// public void onInfoWindowClick() {
// mBaiduMap.hideInfoWindow();
// }
// };
mark点击要这样监听
mBaiduMap.setOnMarkerClickListener(new OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
LogUtil.showlog("OnMarkerClick!!" + marker.getTitle());
if (marker==mMarker) {
runInUi(Global.Flags.chooiceChild, null, false, 0);
}
return false;
}
});
最后显示出来
top = 下移高度,负数上移
mInfoWindow = new InfoWindow(bitmap, ll, top, listener);