【发布时间】:2018-03-24 23:32:25
【问题描述】:
我正在开发 Android Weather 应用程序,我的要求是显示动画预报。我们有一个服务器,我使用 Glide 将预测图像加载为位图,然后使用位图创建 GoogleMap 的 GroundOveryayOption。 我正在使用 Runnable 和 Handler 制作动画。
除了内存消耗外,一切正常,最终我得到“内存不足异常”
为了顺利运行我的预测动画,我必须使用 Glide 加载所有位图并从位图创建 GroundOverlayOptions obj 并将 GroundOverlayOptions 存储在 HashMap 中,如下所示。
@Override
public void onResourceReady(@NonNull Bitmap bitmap, @Nullable Transition<? super Bitmap> transition) {
mBitmapLoaded = true;
//the actual image is png and its size is in KBs but Bitmap size is in MBs
Log.i("Weather", ""+ bitmap.getByteCount());
GroundOverlayOptions overlayOptions = new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromBitmap(bitmap))
.positionFromBounds(getLatLngBounds(mBounds))
.visible(frameVisible);
//groundOverlaysItemMap is a Hashmap to store GroundOverlayOptions where key is Time
groundOverlaysItemMap.put(mTime, mMap.addGroundOverlay(overlayOptions));
}
感谢任何帮助。
【问题讨论】:
-
您可能只想将 .png 文件保存在内存中,并且仅在需要时才绘制它们,以便在任何时候都只有其中一个处于解压缩形式。更多 CPU 使用率,更多更少 RAM 使用率。
-
我需要提前创建 GroundOverlayOption 对象,以免影响动画如下 GroundOverlayOptions overlayOptions = new GroundOverlayOptions() .image(BitmapDescriptorFactory.fromBitmap(bitmap)) .positionFromBounds(getLatLngBounds(mBounds)) 。可见(frameVisible);
-
将图像下采样到可以容忍的最低分辨率。
标签: android google-maps