アンドロイドで以下のようなクラスタリングアイコンを変更したいと思います。サークル内には1つのイメージビューと1つのテキストビューがあります。Googleマップクラスタリング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>
出力のための私のコード:
円の中の最初の画像のようなクラスタアイコンを実現したい。私は相対的なレイアウトで円の背景を使用していますが、うまくいきません。 the Google Maps documentation site:
から
私はthat.Butアイコンは、私が円形たいabove.Butのような長方形で示している行っています。 –
それは、それをカスタマイズするためにプログラミングを始める必要があるときです。あなたのコードを投稿してください、何を試してみましたか、どのような結果が得られましたか、正確にあなたのために働いていないものなど –
私は質問を更新しました。チェックしてください。 –