在屏幕上更改setMyLocationEnabled按钮位置

时间:2015-02-15 09:09:09

标签: android button google-maps-android-api-2

在Android上使用Google Maps V2时,我调用函数:

googleMap.setMyLocationEnabled(true);

它给出了地图右上角当前位置的按钮。我想用我的自定义主题将该按钮位置更改为左下角。

我该怎么办?

2 个答案:

答案 0 :(得分:1)

GoogleMap mMap;
mMap.setPadding(int left, int top, int right, int bottom).

来自Google Maps Android API:

  

您可以使用GoogleMap.setPadding()方法在地图边缘添加填充。地图将继续填充整个容器,但文本和控件定位,地图手势和相机移动的行为就像放置在较小的空间中一样。这导致以下更改:   通过API调用或按钮按下(例如,罗盘,我的位置,缩放按钮)的相机移动将相对于填充区域。   getCameraPosition()将返回填充区域的中心。   Projection.getVisibleRegion()将返回填充区域。   UI控件将从容器边缘偏移指定的像素数。

答案 1 :(得分:0)

在onMapReady()方法中添加它

if (mapView != null &&
            mapView.findViewById(Integer.parseInt("1")) != null) {
        // Get the button view
        View locationButton = ((View) mapView.findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
        // and next place it, on bottom right (as Google Maps app)
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)
                locationButton.getLayoutParams();
        // position on right bottom above zoomLayout
        View zoom_in_button = mapView.findViewWithTag("GoogleMapZoomInButton");
        View zoom_layout = (View) zoom_in_button.getParent();
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
        layoutParams.addRule(RelativeLayout.ABOVE, zoom_layout.getId());
        layoutParams.setMargins(0, 0, 30, 30);
    }
相关问题