UPDATE
starting April 1, 2016, a prefix was added to the Library Resources so id = "text" was changed to "amu_text" .
As indicated in the library documentation:
setContentView public void setContentView (View contentView)
Sets the child view for the icon.
If the view contains a TextView with the identifier "text", operations such as setTextAppearance (Context, int) and makeIcon (String) will work on this TextView.
@Override protected void onBeforeClusterRendered(Cluster<Dashboard_Marker> cluster, MarkerOptions markerOptions) { IconGenerator TextMarkerGen = new IconGenerator(context); Drawable marker; int ClusterSize = cluster.getSize(); marker = context.getResources().getDrawable(R.drawable.cluster_red); TextMarkerGen.setBackground(marker); LayoutInflater myInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View activityView = myInflater.inflate(R.layout.cluster_view, null, false); TextMarkerGen.setContentView(activityView); TextMarkerGen.makeIcon(String.valueOf(cluster.getSize())); BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(TextMarkerGen.makeIcon()); markerOptions.icon(icon); }
with layout_view layout like:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:layout_centerInParent="true" android:layout_centerVertical="true" android:weightSum="1"> <TextView android:layout_width="61dp" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Medium Text" android:textColor="#000000" android:id="@+id/text" android:layout_marginTop="13dp" android:gravity="center" /> </LinearLayout>
note: the layout should contain a single text view with id = "text" so that the icon generator can accept it, manipulate all the positioning that you want in the layout.
source share