estoy tratando de establecer una vista para mi clúster de mapas. estoy inflando una vista desde un XML y configurando el texto de acuerdo con el tamaño del clúster y quiero mostrar esa vista. en el siguiente código me sale un mapa de bits nulos a cambio:android convertir vista XML a mapa de bits sin mostrarlo
private Bitmap createClusterBitmap(int clusterSize) {
View cluster = LayoutInflater.from(context).inflate(R.layout.map_cluster, null);
cluster.setText(String.valueOf(clusterSize));
cluster.setDrawingCacheEnabled(true);
cluster.buildDrawingCache(true);
Bitmap bm = cluster.getDrawingCache();
return bm;
}
en el siguiente código me sale puntero nulo en la cuarta línea (el params diseño):
private Bitmap createClusterBitmap(int clusterSize) {
View cluster = LayoutInflater.from(context).inflate(R.layout.map_cluster, null);
TextView clusterSizeText = (TextView) cluster.findViewById(R.map.cluster);
clusterSizeText.setText(String.valueOf(clusterSize));
Bitmap clusterBitmap = Bitmap.createBitmap(cluster.getLayoutParams().width, cluster.getLayoutParams().height, Bitmap.Config.ARGB_8888);
Canvas clusterCanvas = new Canvas(clusterBitmap);
cluster.layout(cluster.getLeft(), cluster.getTop(), cluster.getRight(), cluster.getBottom());
cluster.draw(clusterCanvas);
return clusterBitmap;
}
y al cambiar a el siguiente código no da error pero nada es dibujé:
private Bitmap createClusterBitmap(int clusterSize) {
View cluster = LayoutInflater.from(context).inflate(R.layout.map_cluster, null);
TextView clusterSizeText = (TextView) cluster.findViewById(R.map.cluster);
clusterSizeText.setText(String.valueOf(clusterSize));
Bitmap clusterBitmap = Bitmap.createBitmap(50,50 , Bitmap.Config.ARGB_8888);
Canvas clusterCanvas = new Canvas(clusterBitmap);
cluster.layout(50, 50, 50, 50;
cluster.draw(clusterCanvas);
return clusterBitmap;
}
esta es mi XML:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+map/cluster"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/map_pointer_cluster"
android:gravity="center"
android:orientation="vertical"
android:textColor="@android:color/black"
android:textSize="35dp"
android:textStyle="bold" />
encontró la solución en [esta] [1] respuesta [1]: http://stackoverflow.com/questions/2339429/android-view-getdrawingcache- returns-null-only-null/4618030 # 4618030 –