Canvas.drawText(...)不打印换行符 [英] Canvas.drawText(...) does not print linebreak

查看:272
本文介绍了Canvas.drawText(...)不打印换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着写上我创建了一个表面观一些文本。它工作正常,如果标题是假的,并没有断行添加到文本。但是,如果我添加标题,因此断行,断行不打印预期,而是有这个符号[]打印。

任何提示,为什么?

  @覆盖
公共无效drawObject(){
字符串文本=;
如果(标题){
   文= getGameBoard()getGame()getForeignProfile()的getName()+\ N。;
}
文=文+ getScoreAsString();
。getGameBoard()getCanvas()的drawText(文字,0,text.length()为getPosition()的getX()为getPosition()getY()以,getPaint());
}
 

解决方案

在[]符号可能是您的换行符。无论出于何种原因,的drawText()不知道如何处理换行。

无论是与偏移Y位置来模拟一个换行符脱衣换行,或致电的drawText()的两倍。

I tried to write some text on a surface view I created. It works fine, if title is false, and there is no linebreak added to the text. But if I add a title and therefore a linebreak, the linebreak isn't printed as expected, but instead there is this symbol [] printed.

Any hints why?

@Override
public void drawObject() {
String text = "";
if (title) {
   text = getGameBoard().getGame().getForeignProfile().getName() + "\n";
}
text = text + getScoreAsString();
getGameBoard().getCanvas().drawText(text, 0, text.length(), getPosition().getX(), getPosition().getY(), getPaint());
}

解决方案

The [] symbol is probably your newline character. For whatever reason, drawText() doesn't know how to handle newlines.

Either strip the newline, or call drawText() twice with an offset Y-position to simulate a newline.

这篇关于Canvas.drawText(...)不打印换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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