6

我的应用程序有 1,5 千个标记,通过标记聚类显示。

实际上它适用于默认标记,但我想使用矢量位图并用文本(加油站的价格)渲染标记,如下所示:

![在此处输入图像描述

在完成渲染标记之前,发生此异常:“无法分配 dup blob fd。”

我认为这是某种内存溢出,但我不知道如何解决。有谁知道如何解决这个问题或对如何管理这么多标记有其他建议?

注意:我已经在使用标记聚类。

注意:此问题仅出现在某些摩托罗拉和 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;
}
4

0 回答 0