gpt4 book ai didi

android - 应用填充后异常 View 尺寸太小。 (使用 newLatLngBounds(LatLngBounds,int))

转载 作者:行者123 更新时间:2023-12-04 23:58:11 25 4
gpt4 key购买 nike

我正在开发一个安卓应用。在此应用程序中,我在 fragment 中显示了一个 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);

最佳答案

当 padding 大于 height 时就会出现问题。考虑屏幕高度:

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

关于android - 应用填充后异常 View 尺寸太小。 (使用 newLatLngBounds(LatLngBounds,int)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50993033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com