odpowiedź Sam był mój punkt wyjścia, ale obraz nie pojawi się, tylko tekst (używam go na Google Map). W końcu udało mi się pracować z LayerDrawable
. Oto moje rozwiązanie:
private Drawable createMarkerIcon(Drawable backgroundImage, String text,
int width, int height) {
Bitmap canvasBitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
// Create a canvas, that will draw on to canvasBitmap.
Canvas imageCanvas = new Canvas(canvasBitmap);
// Set up the paint for use with our Canvas
Paint imagePaint = new Paint();
imagePaint.setTextAlign(Align.CENTER);
imagePaint.setTextSize(16f);
// Draw the image to our canvas
backgroundImage.draw(imageCanvas);
// Draw the text on top of our image
imageCanvas.drawText(text, width/2, height/2, imagePaint);
// Combine background and text to a LayerDrawable
LayerDrawable layerDrawable = new LayerDrawable(
new Drawable[]{backgroundImage, new BitmapDrawable(canvasBitmap)});
return layerDrawable;
}
Czy wiesz, jak to zrobić z 9 ścieżkami do rysowania, więc może przyjąć rozmiar tekstu? – Tsunaze
jak by to zrobić, ponieważ BitmapDrawable został zamortyzowany?!? – M4tchB0X3r
Czy wiesz, dlaczego obraz nie pojawił się z odpowiedzią Sama? – pptang