本文介绍了绘制多行文本到画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个希望快速的问题,但我似乎无法找到任何的例子...我想通过写多行文本到自定义查看 画布,而在的OnDraw()我:
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); ...
我希望这会导致换行符,而是我看到神秘的人物,其中 \ñ是
任何指针AP preciated。
Any pointers appreciated.
保
推荐答案不幸的是Android不知道是什么 \ñ是。什么,你需要做的是剥离 \ñ,然后偏移在Y获得下一行文本。因此,像这样:
Unfortunately Android doesn't know what \n is. What you have to do is strip the \n and then offset the Y to get your text on the next line. So something like this:
canvas.drawText("This is", 100, 100, mTextPaint); canvas.drawText("multi-line", 100, 150, mTextPaint); canvas.drawText("text", 100, 200, mTextPaint);更多推荐
绘制多行文本到画布
发布评论