【发布时间】:2017-11-03 00:13:56
【问题描述】:
我的应用程序在地图上大约有 1,500 个标记,这些标记通过集群显示,以免应用程序过载。这些书签目前显示为 BitmapDescriptorFactory.defaultMarker ()
但是,当我修改每个点的代码以显示带有标记值的自定义位图时,只有少数设备出现此错误,其中包括 LG K10 LTE 和一些摩托罗拉。大多数电器工作正常。
当我使用这个函数时,在我完成渲染所有 1500 个标记之前,它会崩溃并出现以下错误:
“无法分配 dup blob fd。”
在对此错误的研究中,在我看来这是内存溢出,我应该将这些标记存储在 LRU 缓存中,但我无法与集群一起执行此操作。
有没有人遇到过这个问题,或者您有解决这个问题的想法/建议?
以下是位图渲染器代码sn-p:
public class OwnRendring extends DefaultClusterRenderer<MyItem> {
OwnRendring(Context context, GoogleMap map, ClusterManager<MyItem> clusterManager) {
super(context, map, clusterManager);
}
protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {
markerOptions.snippet(item.getSnippet());
markerOptions.title(item.getTitle());
markerOptions.anchor(0.33f, 1f);
markerOptions.infoWindowAnchor(0.33f,0f);
int cor = (item.getPublico() ? cfgCorPostoPublico : cfgCorPostoPrivado);
String preço = item.getTitle().substring(item.getTitle().length() - 5);
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(createMarker(preço, cor)));
super.onBeforeClusterItemRendered(item, markerOptions);
}
protected boolean shouldRenderAsCluster(Cluster cluster) {
return cfgCluster && cluster.getSize() >= cfgClusterMin;
}
}
@Override
public void onCameraIdle() {mClusterManager.cluster();}
private Bitmap createMarker(String text, int color) {
View markerLayout = getLayoutInflater().inflate(R.layout.custom_marker, null);
ImageView markerImage = markerLayout.findViewById(R.id.marker_image);
TextView markerRating = markerLayout.findViewById(R.id.marker_text);
markerImage.setImageResource(R.drawable.pin_shadow);
markerImage.clearColorFilter();
markerImage.getDrawable().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY );
markerRating.setText(text);
markerLayout.measure(
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
markerLayout.layout(0, 0, markerLayout.getMeasuredWidth(), markerLayout.getMeasuredHeight());
final Bitmap bitmap = Bitmap.createBitmap(
markerLayout.getMeasuredWidth(),
markerLayout.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
markerLayout.draw(canvas);
return bitmap;
}
【问题讨论】:
标签: android google-maps bitmap marker