2011-09-21 22 views
8

嘗試從覆蓋項目更改標記我注意到setMarker()使項目不可見。這是代碼示例。Android OverlayItem.setMarker():更改一個項目的標記

//Create new marker 
Drawable icon = this.getResources().getDrawable(R.drawable.marker); 

//Set the new marker to the overlay 
overlayItem.setMarker(icon); 
+0

你找到了一個解決方案?我面臨同樣的問題。使用特定的drawable調用setMarker()會使圖標不可見... – MobileCushion

+1

您必須使用'setBounds()' – slybloty

+1

確定工作的邊界矩形,您應該回答該問題;) – MobileCushion

回答

11

外接矩形需要爲可繪製到指定:

//Create new marker 
Drawable icon = this.getResources().getDrawable(R.drawable.marker); 

//Set the bounding for the drawable 
icon.setBounds(
    0 - icon.getIntrinsicWidth()/2, 0 - icon.getIntrinsicHeight(), 
    icon.getIntrinsicWidth()/2, 0); 

//Set the new marker to the overlay 
overlayItem.setMarker(icon); 
0

我相信這會工作:

public void addOverlay(final OverlayItem overlay) 
    { 
     creditOverlay.add(overlay); 
     populate(); 
     boundCenter(customMarker); 
    } 

你將不得不調用boundCenterboundCenterBottom而在地圖覆蓋列表中添加疊加。在SetMarker()只需設置自定義製造商。

+0

這將導致所有項目使用相同的標記,除非方法更改爲:addOverlay(OverlayItem,Drawable) – slybloty