i\'m trying to set a view to my map cluster. i\'m inflating a view from an XML and setting the Text according to cluster size and i want to show that view. in the following
Your cluster.getLayoutParams()
is probably null
. First, you need to measure the width/height of your inflated view and then assign to it. Do it as below:
private Bitmap createClusterBitmap(int clusterSize) {
View cluster = LayoutInflater.from(context).inflate(R.layout.map_cluster,
null);
TextView clusterSizeText = (TextView) cluster.findViewById(R.id.map_cluster_text);
clusterSizeText.setText(String.valueOf(clusterSize));
cluster.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
cluster.layout(0, 0, cluster.getMeasuredWidth(),cluster.getMeasuredHeight());
final Bitmap clusterBitmap = Bitmap.createBitmap(cluster.getMeasuredWidth(),
cluster.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(clusterBitmap);
cluster.draw(canvas);
return clusterBitmap;
}