将多行文本绘制到 Canvas [英] Draw multi-line text to Canvas

查看:41
本文介绍了将多行文本绘制到 Canvas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个希望很快的问题,但我似乎找不到任何示例...我想通过 CanvasViewcode>,在 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
multi-line
text";
canvas.drawText(text, 100, 100, mTextPaint);
...

我希望这会导致换行,但我看到的是 所在的神秘字符.

I was hoping this would result in line breaks, but instead I am seeing cryptic characters where the would be.

感谢任何指点.

保罗

推荐答案

不幸的是,Android 不知道 是什么.您需要做的是去除 ,然后偏移 Y 以使您的文本出现在下一行.所以是这样的:

Unfortunately Android doesn't know what is. What you have to do is strip the 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);

这篇关于将多行文本绘制到 Canvas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆