在Android画布包皮过长的文本 [英] Wrapping long text on an Android Canvas

查看:149
本文介绍了在Android画布包皮过长的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的控件是做了很多2D直画到画布

I have a custom control that is doing a lot of 2D drawing straight to the canvas.

部分此图的是文本,所以我使用的<一个href="http://developer.android.com/reference/android/graphics/Canvas.html#drawText%28java.lang.String,%20int,%20int,%20float,%20float,%20android.graphics.Paint%29"><$c$c>Canvas.drawText()方法。

Some of this drawing is text, so I am using the Canvas.drawText() method.

欲绘制一些范围内的文本 - 一个左上,特定的最大宽度,并且线的最大数目。绘制文本后,我想知道有多少行花了。

I want to draw the text within some bounds - a top-left, certain maximum width, and a maximum number of lines. After drawing the text, I want to know how many lines it took.

有一个内置的功能来绘制边界内做分裂明智的文字?

Is there a built-in function to draw text within bounds doing the splitting sensibly?

如果不是,是否有一个标准的配方,这样做?

If not, is there a standard recipe for doing so?

推荐答案

您可以使用<一个href="http://developer.android.com/reference/android/text/Layout.html"><$c$c>android.text.StaticLayout类此,只需创建一个 StaticLayout 所需的文本,对齐方式,宽度等,并调用它的画(油画)方法画在画布上。

You can use the android.text.StaticLayout class for this; simply create a StaticLayout for the desired text, alignment, width, etc. and call its draw(Canvas) method to draw to the canvas.

这篇关于在Android画布包皮过长的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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