我希望我的标记与我用Volley下载的图像一起使用。它的作用应该是什么样子。问题是当我点击一组引脚(使用Cluster Manager制作)时,应用程序变得非常无响应并且因内存不足消息而崩溃。这是我的代码:
class MyClusterRenderer extends DefaultClusterRenderer<MarkerItem> {
Context currentContext;
public MyClusterRenderer(Context context, GoogleMap map,
ClusterManager<MarkerItem> clusterManager) {
super(context, map, clusterManager);
currentContext = context;
}
@Override
protected void onBeforeClusterItemRendered(MarkerItem item, MarkerOptions markerOptions) {
super.onBeforeClusterItemRendered(item, markerOptions);
}
@Override
protected void onClusterItemRendered(MarkerItem clusterItem, Marker marker) {
super.onClusterItemRendered(clusterItem, marker);
createMarker(clusterItem, marker);
}
private void createMarker(MarkerItem clusterItem, final Marker marker) {
ImageRequest request = new ImageRequest(clusterItem.getImageUrl(), new Response.Listener<Bitmap>() {
public void onResponse(Bitmap responseBitMap) {
// set for small marker
int radius = 160;
int stroke = 6;
double verticalAnchor = 0.944f;
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Bitmap bmp = Bitmap.createBitmap((int) radius, (int) radius + 25, conf);
Canvas canvas = new Canvas(bmp);
// creates a centered bitmap of the desired size
responseBitMap = ThumbnailUtils.extractThumbnail(responseBitMap, (int) radius - stroke, (int) radius - stroke, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
BitmapShader shader = new BitmapShader(responseBitMap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(0xff464646);
paint.setStyle(Paint.Style.FILL);
// the triangle laid under the circle
int pointedness = 20;
Path path = new Path();
path.setFillType(Path.FillType.EVEN_ODD);
path.moveTo(radius / 2, radius + 15);
path.lineTo(radius / 2 + pointedness, radius - 10);
path.lineTo(radius / 2 - pointedness, radius - 10);
canvas.drawPath(path, paint);
// gray circle background
RectF rect = new RectF(0, 0, radius, radius);
canvas.drawRoundRect(rect, radius / 2, radius / 2, paint);
// circle photo
paint.setShader(shader);
rect = new RectF(stroke, stroke, radius - stroke, radius - stroke);
canvas.drawRoundRect(rect, (radius - stroke) / 2, (radius - stroke) / 2, paint);
marker.setIcon(BitmapDescriptorFactory.fromBitmap(bmp));
}
}, 100, 100, null, null, new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
Log.i("Sharing", "Error");
}
});
request.setShouldCache(true);
Volley.newRequestQueue(currentContext).add(request);
}
}
以下是错误消息:
W / art:暂停所有线程:21.942ms W / libc:pthread_create失败:无法分配1064960字节堆栈:内存不足 E / art:抛出OutOfMemoryError&#34; pthread_create(1040KB堆栈)失败:再试一次&#34;