java set callout image mapbox 安卓
在iOS中,您可以通过调用以下命令轻松设置标记的标注:
[marker setCanShowCallout:YES];
[marker setRightCalloutAccessoryView:YOUR_BUTTON];
但是我找不到Mapbox Android SDK的这个功能。我现在有一个监听器,可以检测callout视图上的触碰,但我如何设置callout图像/按钮
Marker marker = new Marker(p.getTitle(), p.getCatagoryName(), new LatLng(p.getLatitude(), p.getLongitude()));
marker.setMarker(getResources().getDrawable(getResources().getIdentifier(string, "drawable", getActivity().getPackageName())));
mMapView.addMarker(marker);
InfoWindow toolTip = marker.getToolTip(mMapView);
View view = toolTip.getView();
// view.setBackgroundResource(R.drawable.callout_button); THIS DOES NOT WORK
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
Log.e(TAG, "onTouch");
return true;
}
});
# 1 楼答案
您必须自己构建此功能,但通过定义自定义标记和工具提示布局,实际上很容易实现
从定义工具提示布局开始。显然,它必须是一个相对位置来定位标注图像。将上下文设置为创建标记的任何活动。必须包括底部的TipView,因为它控制自定义工具提示的大小
然后创建一个自定义标记类并重写createTooltip方法,以返回一个具有新布局的信息窗口:
这不应该改变任何其他功能,因此您的代码仍然可以工作。只需将Marker更改为自定义类名,就可以设置
编辑:下面是用我的地图实际设置CustomMarker和InfoWindow的代码。你可以看到我在点击时启动了另一个活动,并且我已经为标记设置了一个自定义图标,但这不是必需的:
我也在使用SDK 0.5.0-SNAPSHOT。我不确定这是否适用于旧版本的SDK
# 2 楼答案
ryansh的出色响应要求我在自定义布局中包含带有ids tooltip_title和tooltip_description的文本视图。我还必须添加第三个工具提示_子描述文本视图。默认的InfoWindow代码假定这些视图存在,如果它们不存在,就会崩溃。为了获得更多控制,我扩展了InfoWindow,覆盖了onOpen,并且能够使用工具提示所需的任何布局。对于扩展标记类中被重写的createTooltip,我自然地实例化并返回了扩展的InfoWindow对象
更新。下面是一个扩展标记的示例&;支持自定义工具提示的信息窗口: