【问题标题】:Change setMyLocationEnabled button location on screen更改屏幕上的 setMyLocationEnabled 按钮位置
【发布时间】:2015-02-15 09:09:08
【问题描述】:

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

googleMap.setMyLocationEnabled(true);

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

我该怎么办?

【问题讨论】:

  • 我认为不可能。
  • @greywolf82 在 android 的 Google Maps 默认应用程序中,该按钮位于 RIGHT-BOTTOM 中。那我觉得应该是可以的。

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


【解决方案1】:
GoogleMap mMap;
mMap.setPadding(int left, int top, int right, int bottom).

来自 Google Maps Android API:

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

【讨论】:

    【解决方案2】:

    将此添加到您的 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);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-03
      • 1970-01-01
      • 2012-03-17
      • 2021-05-01
      • 1970-01-01
      相关资源
      最近更新 更多