我的应用程序有1,5,000个标记,通过标记聚类显示。
实际上它可以正常使用默认标记,但我想使用矢量位图并使用文本(加油站价格)渲染标记,如下所示:
在完成渲染标记之前,会发生以下异常:“无法分配dup blob fd。”
我认为这是某种内存溢出,但我不知道如何解决它。 有没有人知道如何解决这个问题,或者有另外一个如何管理这么多标记的建议?
注意:我已经在使用标记聚类。
注意:仅在某些Motorola和LG设备上会出现此问题。在大多数设备工作正常。 一些代码:
public class OwnRendring extends DefaultClusterRenderer<MyItem> {
public 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;
if (item.getPublico()) {
cor=cfgCorPostoPublico;
} else {
cor=cfgCorPostoPrivado;
}
String preço = item.getTitle().substring(item.getTitle().length() - 5);
if (Objects.equals(preço, "0,000")) { preço=""; }
Bitmap bitmap = createStoreMarker(preço, cor);
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
super.onBeforeClusterItemRendered(item, markerOptions);
}
protected boolean shouldRenderAsCluster(Cluster cluster) {
// if markers < cfgClusterMin then not clustering
return cfgCluster && cluster.getSize() >= cfgClusterMin;
}
}
private Bitmap createStoreMarker(String text, int color) {
View markerLayout = getLayoutInflater().inflate(R.layout.custom_marker, null);
ImageView markerImage = (ImageView) markerLayout.findViewById(R.id.marker_image);
TextView markerRating = (TextView) 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;
}