android.view.InflateException: Binary XML file line #53: Error inflating class Button 오류가 떠 검색해본 결과 API 버전이 너무 낮아서 v-24를 사용할 수 없던 것이다.
// 마커 커스텀 class
class CustomIconRenderer extends DefaultClusterRenderer<ClusterData> {
private final IconGenerator mClusterIconGenerator = new IconGenerator(getApplicationContext());
Context context;
public CustomIconRenderer(Context context, GoogleMap map, ClusterManager<ClusterData> clusterManager) {
super(context, map, clusterManager);
this.context = context;
}
@Override
protected void onBeforeClusterItemRendered(ClusterData item, MarkerOptions markerOptions) {
tv_marker.setText(item.gettitle());
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(createDrawableFromView(context, marker_root_view)));
super.onBeforeClusterItemRendered(item, markerOptions);
}
@Override
protected void onBeforeClusterRendered(Cluster item, MarkerOptions markerOptions){
final Drawable clusterIcon = getResources().getDrawable(R.drawable.cluster_background);
mClusterIconGenerator.setBackground(clusterIcon);
View clusterView = LayoutInflater.from(context).inflate(R.layout.clustertext, null, false);
mClusterIconGenerator.setContentView(clusterView);
mClusterIconGenerator.makeIcon(String.valueOf(item.getSize()));
Bitmap icon = mClusterIconGenerator.makeIcon();
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
}
// View를 Bitmap으로 변환
private Bitmap createDrawableFromView(Context context, View view) {
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
view.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
view.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}
}
if (clusterManager == null){
clusterManager = new ClusterManager<>(this,map);
clusterManager.setRenderer(new CustomIconRenderer(this,map,clusterManager));
getData(type); // cluster.add()
}