Я хочу изменить значок кластеризации, как показано ниже в android. В круге будет одно изображение и одно текстовое изображение.Google map clustering in android
Мой код для пользовательского значка
private class ItemRenderer extends DefaultClusterRenderer<ClusterPopupList> {
private final IconGenerator mIconGenerator = new IconGenerator(getApplicationContext());
private final IconGenerator mClusterIconGenerator = new IconGenerator(getApplicationContext());
private final int mDimension;
public ItemRenderer() {
super(getApplicationContext(), map, mClusterManager);
View multiProfile = getLayoutInflater().inflate(R.layout.multi_profile,null);
mClusterIconGenerator.setContentView(multiProfile);
mImageView = new ImageView(getApplicationContext());
mDimension = (int) getResources().getDimension(R.dimen.custom_profile_image);
mImageView.setLayoutParams(new ViewGroup.LayoutParams(mDimension, mDimension));
mIconGenerator.setContentView(mImageView);
}
@Override
protected void onBeforeClusterItemRendered(ClusterPopupList item, MarkerOptions markerOptions) {
mImageView.setImageResource(item.profilePhoto);
Bitmap icon = mIconGenerator.makeIcon();
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
super.onBeforeClusterItemRendered(item, markerOptions);
}
@Override
protected void onBeforeClusterRendered(Cluster<ClusterPopupList> cluster, MarkerOptions markerOptions) {
List<Drawable> profilePhotos = new ArrayList<Drawable>(Math.min(4, cluster.getSize()));
int width = mDimension;
int height = mDimension;
for (ClusterPopupList p : cluster.getItems()) {
// Draw 4 at most.
if (profilePhotos.size() == 4) break;
Drawable drawable = getResources().getDrawable(p.profilePhoto);
drawable.setBounds(0, 0, width, height);
profilePhotos.add(drawable);
}
Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
}
@Override
protected void onClusterRendered(Cluster<ClusterPopupList> cluster, Marker marker) {
super.onClusterRendered(cluster, marker);
}
@Override
public ClusterPopupList getClusterItem(Marker marker) {
return super.getClusterItem(marker);
}
@Override
protected boolean shouldRenderAsCluster(Cluster<ClusterPopupList> cluster) {
return cluster.getSize() > 1;
}
}
multi_profile.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@android:color/transparent"
android:src="@drawable/icon_cluster_count"/>
<TextView
android:id="@id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/Bubble.TextAppearance.Light"
android:paddingLeft="@dimen/custom_profile_padding"
android:paddingRight="@dimen/custom_profile_padding"
android:layout_below="@id/image"
android:text="150"
android:layout_centerHorizontal="true"
android:layout_marginBottom="8dip"
android:textColor="@color/theme_color"
android:alpha=".8"/>
</RelativeLayout>
Выход:
Я хочу получить значок кластера, как первое изображение в круге. Я использовал кругный фон в относительной компоновке, но это не работает.
Я сделал that.but значок показывается в виде прямоугольника, как above.But я хочу круговой. –
Ну, когда вам нужно начать программирование, чтобы настроить его так, как вы этого хотите. Отправьте свой код, что вы пробовали, какие результаты у вас были, что именно не работает для вас и т. Д. –
Я обновил вопрос. Пожалуйста, проверьте. –