2015-02-24 76 views
1

我正在使用Google Maps API for Android。下面的代碼能夠在右下角的工具欄的地圖,當我一個標記,點擊Android:Google Maps API - 更改地圖工具欄的位置

googleMap.getUiSettings().setMapToolbarEnabled(true); 

不過,我想這個映射工具欄出現在地圖的右上角,而不是默認的底部正確的位置。

我該怎麼做?

+0

使用如下所示的地圖填充:http://stackoverflow.com/a/20339849/2401535 – 2015-02-24 08:41:32

+0

謝謝 - 這工作!直到有一個明確的方法來改變地圖工具欄的位置,這將做:) – 2015-02-24 21:01:09

回答

5

想法評論,但信譽低。所以:

據我所知,目前無法定位它。它只會出現在其默認位置。

正如Nathan所說,如果可能的話,我應該添加一些替代方案。所以,有一個解決方法:你可以禁用地圖的工具欄。並可以在佈局的任何位置添加appcompact的ToolBar。

參考:https://developer.android.com/reference/android/support/v7/widget/Toolbar.html

+2

我會建議,如果可能的話,改變這一點,沿着「你不能,但這裏是你可以做的事情「。 – 2015-02-24 05:32:18

+0

當然,但一定有_something_,他可以做。 – 2015-02-24 05:38:42

+0

對。如果你能解釋什麼可能是什麼,那麼這將是一個完全合法的答案。否則,不是那麼多。 – 2015-02-24 05:39:45

11

這是我碰到前爲如何將工具欄移動到頁面底部的答案。我希望這可以幫助你。

//get reference to my location icon 
    View locationButton = ((View) mapFragment.getView().findViewById(Integer.parseInt("1")). 
      getParent()).findViewById(Integer.parseInt("2")); 

    // and next place it, for example, on bottom right (as Google Maps app) 
    RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams(); 
    // position on right bottom 
    rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0); 
    rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); 
    rlp.setMargins(0, 0, 30, 30); 

編輯: 按照建議(@Andro的),這是改變地圖工具欄的位置代碼:

//獲取參考我的位置圖標

View toolbar = ((View) mapFragment.getView().findViewById(Integer.parseInt("1")). 
      getParent()).findViewById(Integer.parseInt("4")); 

    // and next place it, for example, on bottom right (as Google Maps app) 
    RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) toolbar.getLayoutParams(); 
    // position on right bottom 
    rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0); 
    rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); 
    rlp.setMargins(0, 0, 30, 30); 
+0

'View locationButton =((View)mapFragment.getView()。findViewById(Integer.parseInt(「1」))。 getParent())。findViewById(Integer.parseInt(「4 「)); '地圖工具欄 – Andro 2015-10-29 08:21:58

+0

謝謝你,但你應該編輯你的答案@Andro建議 – Tony 2015-10-31 13:28:48

+0

爲什麼'parseInt(「4」)'? – MetaSnarf 2015-11-02 02:07:39