艾登弗萊的答覆工作,如果你實際顯示信息窗口。如果你不這樣做,標記將不會出現在前面。這是一個黑客,使之走到前面反正:
創建顯示0dp信息窗口自定義InfoWindowAdapter:
public class MapWindowAdapter implements GoogleMap.InfoWindowAdapter {
private Context context = null;
public MapWindowAdapter(Context context) {
this.context = context;
}
// Hack to prevent info window from displaying: use a 0dp/0dp frame
@Override
public View getInfoWindow(Marker marker) {
View v = ((Activity) context).getLayoutInflater().inflate(R.layout.no_info_window, null);
return v;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
}
下面是佈局的代碼:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="0dp">
</LinearLayout>
設置地圖時,設置適配器和自定義InfoWindowAdapter和OnMarkerClickListener(使用showInfoWindow並按照AIden Fry的建議返回true):
mMap.setInfoWindowAdapter(new MapWindowAdapter(this));
//Call showInfoWindow to put marker on top of others.
myMarker.showInfoWindow();
這並不美麗,但我沒有找到任何其他方式來處理z-indexing而不使用信息窗口。
這是正確的答案。對於這樣的基本任務必須做到骯髒的黑客真是太遺憾了。 – lukas 2013-07-17 14:57:09
順便說一下,設置標題不是必需的。 – lukas 2013-07-17 15:03:50
這工作。不過,不需要實現setOnMarkerClickListener。只需按上面所述設置InfoWindowAdapter,然後調用showInfoWindow將標記設置在最前面。 – 2014-02-11 15:02:28