A hopefully quick question, but I can't seem to find any examples... I'd like to write multi-line text to a custom View
via a Canvas
, and in onDraw()
I have:
...
String text = "This is\nmulti-line\ntext";
canvas.drawText(text, 100, 100, mTextPaint);
...
I was hoping this would result in line breaks, but instead I am seeing cryptic characters where the \n
would be.
Any pointers appreciated.
Paul
I have written complete example
colors.xml
java class
try this
I have to add here my version which considers STROKE WIDTH as well.
it will work. i tested
Source : http://www.skoumal.net/en/android-drawing-multiline-text-on-bitmap/
I worked with what I had, which already converted single lines to canvases, and I worked off Lumis's answer, and I ended up with this. The 1.3 and 1.3f are meant as padding between lines, relative to the size of the font.
This is my solution that is based on @Dave's answer (thanks btw ;-) )
I tried to inherit Canvas, but it doesn't really let you. So this is an in-between class!