1

I'm trying to create a custom view, which has a rectangle, and some text right above and below it. So far I am successful at getting text above the rectangle painted, using drawTextOnPath method. However, the one that should go below the rectangle, gets painted upside down. Could I get some advice on how to paint text right below the rectangle?

Thanks in advance!

Mario
  • 335
  • 7
  • 20

1 Answers1

1

The text's baseline follows the path you provide in drawTextOnPath. Therefore, if the baseline (the bottom of the text) that the text is to follow is going from right to left the text would be upside down. To make it the right way up have to know or measure the height of the text and then draw it that much farther down. If the path you are using is just a line, perhaps using drawText with just coordinates is better?

Ribose
  • 2,223
  • 16
  • 22
  • But if I use coordinates, doesn't I tie up with concretes coordinates? Are these coordinates valid in canvas area? – Mario Jul 10 '11 at 17:59
  • The coordinates are the same as using coordinates in your Path object. They will be affected by canvas operations like translate() and scale(). Just use drawText(String text, float x, float y, Paint paint). I just tested to be sure in my own project and x = the left bound of the text and y = the bottom (baseline) of the text. – Ribose Jul 10 '11 at 18:26
  • Also, drawTextOnPath is a pretty cool function too if you wanted text to follow a curve or any custom path, for example. :) – Ribose Jul 10 '11 at 18:28