【问题标题】:Exception View size is too small after padding is applied. (using newLatLngBounds(LatLngBounds, int))应用填充后异常视图大小太小。 (使用 newLatLngBounds(LatLngBounds, int))
【发布时间】:2020-06-11 12:16:30
【问题描述】:

我正在开发一个安卓应用程序。在这个应用程序中,我在片段中显示了一个 MapView。当我在 Activity 中包含以下代码时,我的应用程序崩溃了。

 LatLngBounds.Builder builder = new LatLngBounds.Builder();
 builder.include(pickupLatLng);
 builder.include(destinationLatLng);
 LatLngBounds bounds = builder.build();

 int width = getResources().getDisplayMetrics().widthPixels;
 int padding = (int) (width*0.2);

 CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding);
 mMap.animateCamera(cameraUpdate);
 mMap.addMarker(new MarkerOptions().position(pickupLatLng).title("pickup location").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_pickup)));
 mMap.addMarker(new MarkerOptions().position(destinationLatLng).title("destination"));

在这一行显示错误:

mMap.animateCamera(cameraUpdate);

【问题讨论】:

  • 你能分享完整准确的错误信息吗?
  • 出了什么问题?

标签: android google-maps


【解决方案1】:

当内边距大于高度时会出现问题。考虑屏幕高度:

int width = getResources().getDisplayMetrics().widthPixels;
int height = getResources().getDisplayMetrics().heightPixels;
int padding = (int) (Math.min(width, height)*0.2);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-23
    • 2016-01-07
    • 2012-11-18
    • 2020-02-14
    • 1970-01-01
    • 2019-07-15
    • 1970-01-01
    • 2023-04-04
    相关资源
    最近更新 更多