有谁知道您是否可以更改地图内的指南针位置?如何移动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