2016-09-26 2 views
0

안드로이드에서 아래와 같이 클러스터링 아이콘을 변경하고 싶습니다. 원 안에는 하나의 이미지 뷰와 하나의 텍스트 뷰가 있습니다.Google지도 클러스터링 android

enter image description here

사용자 정의 아이콘에 대한 나의 코드

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> 

출력 :

enter image description here

원안의 첫 번째 이미지와 같은 클러스터 아이콘을 얻고 싶습니다. 상대 레이아웃에서 원 배경을 사용했지만 효과가 없습니다. the Google Maps documentation site:

가입일

답변

0

ClusterManager 생성자는 DefaultClusterRendererNonHierarchicalDistanceBasedAlgorithm 생성 마커 클러스터

맞춤. setAlgorithm(Algorithm<T> algorithm)setRenderer(ClusterRenderer<T> view) methods of ClusterManager을 사용하여 ClusterRenderer 및 알고리즘을 변경할 수 있습니다.

ClusterRenderer을 구현하여 클러스터 렌더링을 사용자 정의 할 수 있습니다. DefaultClusterRenderer은 좋은 출발점을 제공합니다. DefaultClusterRenderer을 하위 클래스 화하면 기본값을 무시할 수 있습니다.

enter image description here

+0

내가 암튼 아이콘 내가 원하고자 above.But 같은 사각형에 표시됩니다 했어요. –

+0

글쎄, 당신이 원하는 방식으로 그것을 사용자 정의 프로그래밍을 시작해야 할 때. 코드 게시, 시도한 작업, 결과, 정확하게 작동하지 않는 작업 등 –

+0

질문을 업데이트했습니다. 확인해주십시오. –