我的目标:我想在osmdroid-marker
旁边显示一个弹出菜单我的问题:
目前我将菜单附加到右下角的图像,但可能远离当前标记。
public class LocationMapFragment extends DialogFragment {
...
protected boolean showContextMenu(final View parent, final int markerId,
final IGeoPoint geoPosition, final Object markerData) {
MenuInflater inflater = getActivity().getMenuInflater();
// currently the contextmenu is attached to some image "this.mImage"
// which does not correspont to "geoPosition"
// How to create a temporary 1x1 view at "geoPosition"
// where i can attach the menu to?
PopupMenu menu = new PopupMenu(getActivity(), this.mImage);
inflater.inflate(R.menu.menu_map_context, menu.getMenu());
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.cmd_gallery:
return showGallery(getiGeoPointById(markerId, geoPosition));
case R.id.cmd_zoom:
return zoomToFit(getiGeoPointById(markerId, geoPosition));
default:
return false;
}
}
});
menu.show();
return true;
}
}
我的问题:有没有一种简单的方法可以在我IGeoPoint geoPosition
的标记上创建一个临时1x1像素窗口,我可以将弹出窗口附加到?
还是有其他简单的方法来定位菜单吗?
答案 0 :(得分:1)
使用OSMBonusPack Marker InfoWindow(标记气泡)。
您可以使用infowindow.getView()获取其视图,这是一个常规的android.view.View。
您可以设计其布局,使其尽可能小。
答案 1 :(得分:0)
与MKer一样,您可以使用OSMBonusPack Marker InfoWindow并自定义您自己的InfoWindow。 https://mobiledevstories.wordpress.com/2014/03/01/osmdroid-bonus-pack-markers-with-clickable-infowindows/
答案 2 :(得分:0)
这是我的最终解决方案。 createTempPopupParentMenuView(GeoPoint position)
包含从InfoWindow
中提取的代码,用于在标记位置为popupMenu提供视图:
/** temporary 1x1 pix view where popup-menu is attached to */
private View tempPopupMenuParentView = null;
...
protected boolean showContextMenu(final View parent, final int markerId,
final IGeoPoint geoPosition, final Object markerData) {
MenuInflater inflater = getActivity().getMenuInflater();
mMapView.removeView(tempPopupMenuParentView);
PopupMenu menu = new PopupMenu(getActivity(), createTempPopupParentMenuView(new GeoPoint(geoPosition.getLatitudeE6(), geoPosition.getLongitudeE6())));
inflater.inflate(R.menu.menu_map_context, menu.getMenu());
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
mMapView.removeView(tempPopupMenuParentView);
switch (item.getItemId()) {
case R.id.cmd_gallery:
return showGallery(getiGeoPointById(markerId, geoPosition));
case R.id.cmd_zoom:
return zoomToFit(getiGeoPointById(markerId, geoPosition));
default:
return false;
}
}
});
menu.show();
return true;
}
// inspired by org.osmdroid.bonuspack.overlays.InfoWindow
private View createTempPopupParentMenuView(GeoPoint position) {
if (tempPopupMenuParentView != null) mMapView.removeView(tempPopupMenuParentView);
tempPopupMenuParentView = new View(getActivity());
MapView.LayoutParams lp = new MapView.LayoutParams(
1,
1,
position, MapView.LayoutParams.CENTER,
0, 0);
tempPopupMenuParentView.setVisibility(View.VISIBLE);
mMapView.addView(tempPopupMenuParentView, lp);
return tempPopupMenuParentView;
}
坦克向@MKer指导我走向正确的方向。