Reputation: 75
I have a bitmap and a text. I just wanted to place a text over my bitmap but the problem is the text is drawn behind the bitmap. Can anyone help me?
canvas.drawText("10", (mazeFinishX1 * totalCellWidth)
+ (cellWidth / 10), (mazeFinishY1 * totalCellHeight)
+ (cellHeight * 0.75f), ball);
canvas.drawBitmap(lvl1_portal1, (mazeFinishX1 * totalCellWidth)
+ (cellWidth / 20), (mazeFinishY1 * totalCellHeight)
+ (cellWidth / 20), ball);
I already test it. the text appears behind the bitmap.
Upvotes: 0
Views: 383
Reputation: 1266
Use this code. You draw in wrong order.
canvas.drawBitmap(lvl1_portal1, (mazeFinishX1 * totalCellWidth)
+ (cellWidth / 20), (mazeFinishY1 * totalCellHeight)
+ (cellWidth / 20), ball);
canvas.drawText("10", (mazeFinishX1 * totalCellWidth)
+ (cellWidth / 10), (mazeFinishY1 * totalCellHeight)
+ (cellHeight * 0.75f), ball);
Upvotes: 0
Reputation: 38098
First draw the bitmap, then the text.
canvas.drawBitmap(lvl1_portal1, (mazeFinishX1 * totalCellWidth)
+ (cellWidth / 20), (mazeFinishY1 * totalCellHeight)
+ (cellWidth / 20), ball);
canvas.drawText("10", (mazeFinishX1 * totalCellWidth)
+ (cellWidth / 10), (mazeFinishY1 * totalCellHeight)
+ (cellHeight * 0.75f), ball);
Order matters.
Upvotes: 1