我正在使用一些 .png 文件将叠加层添加到地图中。它工作正常,但有时会抛出位图大小超过 VM 预算错误。当将图像添加到列表视图时发生同样的问题时,我通过应用 SoftReference 解决了它。但我不知道如何应用它在地图视图中添加叠加层。请有任何想法。谢谢
像这样添加叠加层
public ItemizedOverlayMarker(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
像这样调用 ItamizerOverlay :
final List<Overlay> mapOverlaysResult = mapView.getOverlays();
Drawable drawableResult = getResources().getDrawable(R.drawable.pin_pink);
final ItemizedOverlayMarker itemizedoverlayResult = new ItemizedOverlayMarker(drawableResult, this);
for (int i = 0; i < Constants.listOfPlaces.size(); i++) {
GeoPoint geoPoint = new GeoPoint((int)(Double.parseDouble(latitude) * 1E6), (int)(Double.parseDouble(longitude) * 1E6));
OverlayItem overlayitem = new OverlayItem(geoPoint, name, vicinity);
itemizedoverlayResult.addOverlay(overlayitem);
}