Ben @ bishop87 en geçici çözüm from issue on github project basitleştirilmiş sürümünü kullanın. Ayrıca, daha fazla OOM güvenli hale getiren küme bitmapleri için önbelleğe alma ekledi.
bunu kullanabilir veya kendi için bu kodu taşımak daha Küme oluşturucusunu yoksa:
SimpleClusterRenderer.java
public class SimpleClusterRenderer extends DefaultClusterRenderer<AuctionItem> {
private static final int CLUSTER_PADDING = 12;
private static final int ITEM_PADDING = 7;
private final Bitmap mIconItemGreen;
private final IconGenerator mIconClusterGenerator;
private final float mDensity;
public SimpleClusterRenderer(Context context, GoogleMap map, ClusterManager<AuctionItem> clusterManager) {
super(context, map, clusterManager);
mDensity = context.getResources().getDisplayMetrics().density;
mIconClusterGenerator = new CachedIconGenerator(context);
mIconClusterGenerator.setContentView(makeSquareTextView(context, CLUSTER_PADDING));
mIconClusterGenerator.setTextAppearance(com.google.maps.android.R.style.ClusterIcon_TextAppearance);
IconGenerator iconItemGenerator = new IconGenerator(context);
iconItemGenerator.setContentView(makeSquareTextView(context, ITEM_PADDING));
iconItemGenerator.setBackground(makeClusterBackground(ContextCompat.getColor(context, R.color.simple_green)));
mIconItemGreen = iconItemGenerator.makeIcon();
}
@Override
protected void onBeforeClusterItemRendered(AuctionItem item, MarkerOptions markerOptions) {
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(mIconItemGreen));
}
@Override
protected void onBeforeClusterRendered(Cluster<AuctionItem> cluster, MarkerOptions markerOptions) {
int clusterSize = getBucket(cluster);
mIconClusterGenerator.setBackground(makeClusterBackground(getColor(clusterSize)));
BitmapDescriptor descriptor = BitmapDescriptorFactory.fromBitmap(mIconClusterGenerator.makeIcon(getClusterText(clusterSize)));
markerOptions.icon(descriptor);
}
@Override
protected boolean shouldRenderAsCluster(Cluster<AuctionItem> cluster) {
// Always render clusters.
return cluster.getSize() > 1;
}
private int getColor(int clusterSize) {
float size = Math.min((float) clusterSize, 300.0F);
float hue = (300.0F - size) * (300.0F - size)/90000.0F * 220.0F;
return Color.HSVToColor(new float[]{hue, 1.0F, 0.6F});
}
private LayerDrawable makeClusterBackground(int color) {
ShapeDrawable mColoredCircleBackground = new ShapeDrawable(new OvalShape());
mColoredCircleBackground.getPaint().setColor(color);
ShapeDrawable outline = new ShapeDrawable(new OvalShape());
outline.getPaint().setColor(0x80ffffff);
LayerDrawable background = new LayerDrawable(new Drawable[]{outline, mColoredCircleBackground});
int strokeWidth = (int) (mDensity * 3.0F);
background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
return background;
}
private SquareTextView makeSquareTextView(Context context, int padding) {
SquareTextView squareTextView = new SquareTextView(context);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
squareTextView.setLayoutParams(layoutParams);
squareTextView.setId(R.id.text);
int paddingDpi = (int) (padding * mDensity);
squareTextView.setPadding(paddingDpi, paddingDpi, paddingDpi, paddingDpi);
return squareTextView;
}
}
CachedIconGenerator.java
public class CachedIconGenerator extends IconGenerator {
private final LruCache<String, Bitmap> mBitmapsCache;
private String mText;
public CachedIconGenerator(Context context) {
super(context);
final int maxMemory = (int) (Runtime.getRuntime().maxMemory()/1024);
// Use 1/8th of the available memory for this memory cache.
final int cacheSize = maxMemory/8;
mBitmapsCache = new LruCache<String, Bitmap>(cacheSize) {
@Override
protected int sizeOf(String key, Bitmap bitmap) {
// The cache size will be measured in kilobytes rather than
// number of items.
return bitmap.getByteCount()/1024;
}
};
}
public Bitmap makeIcon(String text) {
mText = text;
return super.makeIcon(text);
}
@Override
public Bitmap makeIcon() {
if (TextUtils.isEmpty(mText)) {
return super.makeIcon();
} else {
Bitmap bitmap = mBitmapsCache.get(mText);
if (bitmap == null) {
bitmap = super.makeIcon();
mBitmapsCache.put(mText, bitmap);
}
return bitmap;
}
}
}
PS Ayrıca, istediğiniz pin rengiyle R.color.simple_green
'u değiştirmeniz gerekir.
P.P.S. Unutmayın ki, bu yaklaşımın ihmal edilebilir bir performans etkisi vardır. Dolayısıyla, Google Play'in bu sorunu bir sonraki Play Hizmetleri uygulama sürümünde çözmesi halinde, bu çözümü Play Hizmetleri 9.0.83 ve diğerlerine yönelik farklı yaklaşımlarla güncellemek daha iyi olacaktır.
düzeltene kadar suet https://github.com/googlemaps/android-maps-utils/issues/276 – tyczj