有誰知道您是否可以更改地圖內的指南針位置?如何移動Android Google Maps API指南針位置
我能找到的全部是how to enable or disable它。但我需要稍微調整一下,這樣我的覆蓋不會妨礙它。
有誰知道您是否可以更改地圖內的指南針位置?如何移動Android Google Maps API指南針位置
我能找到的全部是how to enable or disable它。但我需要稍微調整一下,這樣我的覆蓋不會妨礙它。
使用GoogleMap.setPadding()方法:
https://developers.google.com/maps/documentation/android/map#map_padding
據我所知,你不能改變羅盤的位置,但您可以禁用它,打造你的私人之一。
+1有趣。讓我們看看是否有人提出瞭解決方法,如果不是,那麼信用就是你的。 – capdragon 2013-02-23 18:33:51
但是這是使用MapView。任何想法與MapFragment? – 2013-09-05 20:31:15
我知道這是一個漫長的時間,這個問題被問,但我前幾天菲爾德在這個問題上我修正了這樣的問題:
try {
assert mapFragment.getView() != null;
final ViewGroup parent = (ViewGroup) mapFragment.getView().findViewWithTag("GoogleMapMyLocationButton").getParent();
parent.post(new Runnable() {
@Override
public void run() {
try {
for (int i = 0, n = parent.getChildCount(); i < n; i++) {
View view = parent.getChildAt(i);
RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) view.getLayoutParams();
// position on right bottom
rlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP,0);
rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
rlp.rightMargin = rlp.leftMargin;
rlp.bottomMargin = 25;
view.requestLayout();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
在這個例子中,我把指南針放在角落右邊。您需要確保在執行此操作時創建了mapFragment,我建議您在MapFragment的「onMapReady」方法中運行代碼。
這是放置在左側rof某些原因! – Paschalis 2017-02-05 09:11:15
@Override
public void onMapReady(GoogleMap map) {
try {
final ViewGroup parent = (ViewGroup) mMapView.findViewWithTag("GoogleMapMyLocationButton").getParent();
parent.post(new Runnable() {
@Override
public void run() {
try {
Resources r = getResources();
//convert our dp margin into pixels
int marginPixels = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, r.getDisplayMetrics());
// Get the map compass view
View mapCompass = parent.getChildAt(4);
// create layoutParams, giving it our wanted width and height(important, by default the width is "match parent")
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(mapCompass.getHeight(),mapCompass.getHeight());
// position on top right
rlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);
//give compass margin
rlp.setMargins(marginPixels, marginPixels, marginPixels, marginPixels);
mapCompass.setLayoutParams(rlp);
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
在2.0地圖api上。
// change compass position
if (mapView != null &&
mapView.findViewById(Integer.parseInt("1")) != null) {
// Get the view
View locationCompass = ((View) mapView.findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("5"));
// and next place it, on bottom right (as Google Maps app)
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
locationCompass.getLayoutParams();
// position on right bottom
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
layoutParams.setMargins(0, 160,30, 0); // 160 la truc y , 30 la truc x
}
OMG !!!謝謝!!! – capdragon 2013-10-03 17:05:00
工程就像一個魅力! – sud007 2015-06-05 10:17:59
不是一個好的解決方案,因爲它會影響相機的位置 – 2018-01-04 14:57:17