gpt4 book ai didi

android - 使用百分比填充的 Google Maps API v2 newLatLngBounds 在多窗口模式下抛出错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:34:58 51 4
gpt4 key购买 nike

我正在使用基于设备 widthpercentage 设置的 padding 将相机设置为 LatLngBounds 动画,这样它就可以在小屏幕上工作设备。

这甚至适用于具有 4 英寸显示屏的小型设备,但是它在 Android 7.0 和之前支持多窗口模式的设备中的多窗口模式下失败,例如。盖乐世 S7。

我在多窗口模式下的设备上遇到以下异常:

Fatal Exception: java.lang.IllegalStateException: Error using newLatLngBounds(LatLngBounds, int, int, int): View size is too small after padding is applied.

这是可疑代码:

private void animateCamera() {

// ...

// Create bounds from positions
LatLngBounds bounds = latLngBounds(positions);

// Setup camera movement
final int width = getResources().getDisplayMetrics().widthPixels;
final int height = getResources().getDisplayMetrics().heightPixels;
final int padding = (int) (width * 0.40); // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding);

mMap.animateCamera(cu);
}

如何正确设置 newLatLngBounds 中的内边距以适用于所有设备宽度和多窗口模式?

最佳答案

解决方案是选择宽度和高度之间的最小度量,因为在多窗口模式下,高度可以小于宽度:

private void animateCamera() {

// ...

// Create bounds from positions
LatLngBounds bounds = latLngBounds(positions);

// Setup camera movement
final int width = getResources().getDisplayMetrics().widthPixels;
final int height = getResources().getDisplayMetrics().heightPixels;
final int minMetric = Math.min(width, height);
final int padding = (int) (minMetric * 0.40); // offset from edges of the map in pixels
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding);

mMap.animateCamera(cu);
}

关于android - 使用百分比填充的 Google Maps API v2 newLatLngBounds 在多窗口模式下抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40224820/

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