Drawing text

Text can be considered a primitive from the point of view of Canvas operations, but we've put it here on its own section, as it's quite important. Instead of starting with the simplest example, as we've just introduced Paths, we'll continue our previous example and draw the text on top of the Path. To draw the text, we'll reuse the Paint object for the Bezier curve, but we'll add some text parameters:

pathPaint.setTextSize(50.f); 
pathPaint.setTextAlign(Paint.Align.CENTER); 

This sets the size of the text and also aligns it to the center of the Path, so every time we add new points, the text position will adapt to remain at the center. To draw the text, we simply call the drawTextOnPath() method:

canvas.drawTextOnPath("Building ...

Get Building Android UIs with Custom Views now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.