在绘制位图上绘制文本

时间:2015-02-08 15:57:07

标签: android eclipse text bitmap

我有位图和文字。我只是想在我的位图上放置一个文本,但问题是文本是在位图后面绘制的。任何人都可以帮助我吗?

     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);

我已经测试过了。文本显示在位图后面。

2 个答案:

答案 0 :(得分:1)

首先绘制位图,然后绘制文本。

 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);

订单很重要。

答案 1 :(得分:0)

使用此代码。你绘制的顺序错误。

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);