Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why my invoke of Canvas.drawText() just doesn't work

Hi all: I'm writing a class that inherit from TextView, and override its onDraw() method, but in the method, my invoke of canvas.drawText() doesn't seems to work, the code just like below:

protected void onDraw(Canvas canvas) {
    // super.onDraw(canvas);
    Paint paint = new Paint();
    paint.setColor(android.graphics.Color.WHITE);
    paint.setTextSize(20);

    String text = "hello";
    canvas.drawText(text, 0, 0, paint);
}
like image 406
Wenlin.Wu Avatar asked Oct 25 '10 03:10

Wenlin.Wu


1 Answers

It isn't drawing anything because the text coordinates are bottom left. Since you're trying to draw on 0,0, it will draw above the screen.

Try changing the last line to:

canvas.drawText(text, 0, 20, paint);
like image 106
dcarneiro Avatar answered Sep 21 '22 21:09

dcarneiro