绘制多行文本到画布

编程入门 行业动态 更新时间:2024-10-09 11:24:55
本文介绍了绘制多行文本到画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

一个希望快速的问题,但我似乎无法找到任何的例子...我想通过写多行文本到自定义查看 画布,而在的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);

更多推荐

绘制多行文本到画布

本文发布于:2023-11-23 00:58:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619539.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:画布

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!