Вот что у меня есть в файле макета:

И вот что я получаю в результате:

Это создает неправильные размеры и кажется, что гравитация текста игнорируется.
(Я создаю растровое изображение, чтобы добавить его в качестве маркера на картах Google)
Вот мой XML:
И мой Java-код:
private Bitmap createStreetLabel(String labelText) {
View cluster = LayoutInflater.from(context).inflate(R.layout.street_label,
null);
TextView clusterSizeText = (TextView) cluster.findViewById(R.id.label_text);
clusterSizeText.setText(labelText);
cluster.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
cluster.layout(0, 0, cluster.getMeasuredWidth(),cluster.getMeasuredHeight());
final Bitmap bitmap = Bitmap.createBitmap(cluster.getMeasuredWidth(),
cluster.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
cluster.draw(canvas);
return bitmap;
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... ct-dimensi
Мобильная версия