Reputation: 713
So I'm using a ClusterManager
to cluster my Markers
, so that the user can have a better experience.
I have actually implemente Google's code, which I found here. Imagine now that my Marker
icon is a ball. I want the background of the icon to be transparent, not white.
On Google's original tutorial they set a ImageView
to the IconGenerator
, like this:
public class MyClusterManagerRenderer extends DefaultClusterRenderer<ClusteredMarker> {
private final IconGenerator mIconGenerator;
private final ImageView mImageView;
public MyClusterManagerRenderer(Context context, GoogleMap googleMap,
ClusterManager<ClusteredMarker> clusterManager){
super(context, googleMap, clusterManager);
mIconGenerator = new IconGenerator(context);
mImageView = new ImageView(context);
mIconGenerator.setContentView(mImageView);
}
@Override
protected void onBeforeClusterItemRendered(ClusteredMarker item, MarkerOptions markerOptions) {
mImageView.setImageResource(item.iconPicture);
Bitmap icon = mIconGenerator.makeIcon();
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)).title(item.user);
}
...
}
I have tried several ways to make my icon transparent, like calling:
mImageView.setBackgroundColor(Color.TRANSPARENT);
but without success. The only way I managed to find a solution is to directly attach my transparent image to the IconGenerator
, like this:
mIconGenerator.setBackground(aContext.getResources().getDrawable(R.drawable.ball));
The downside of this approach is that a ImageView
have some interesting methods that I would like to call, like setPadding
, while the IconGenerator
doesn't have that.
So, is there a way to make my icon transparent, using the ImageView
?
Thank you,
Upvotes: 7
Views: 6995
Reputation: 413
mImageView.setBackgroundColor(null);
That will remove the background and make it transparent. :)
Upvotes: 1
Reputation: 26831
The solution I found is this:
private static final Drawable TRANSPARENT_DRAWABLE = new ColorDrawable(Color.TRANSPARENT);
// Make the background of marker transparent
mIconGenerator.setBackground(TRANSPARENT_DRAWABLE);
Upvotes: 12