获取行数StaticLayout会分裂成文本 [英] Get number of lines StaticLayout will split text into
问题描述
我画一些文本到画布上,并正在使用StaticLayout包裹在屏幕上的文字。我要对齐文本,使文本的底部是在屏幕的底部。
I'm drawing some text onto a canvas, and am using a StaticLayout to wrap the text across the screen. I want to align the text so that the bottom of the text is on the bottom of the screen.
要做到这一点我需要知道StaticLayout有多少行包文成,这样我就可以乘上字体的大小,并从我的组件的高度偏移那么远。
To do this I need to know how many lines the StaticLayout has wrapped the text into, so i can multiply that by the font size, and offset it that much from the height of my component.
这是我的StaticLayout:
This is my StaticLayout:
main = new TextPaint();
main.setTextSize(textSize);
main.setColor(Color.WHITE);
bottomText = new StaticLayout("Long text that requires wrapping.", main, getWidth(), Layout.Alignment.ALIGN_CENTER, 1f, 1.0f, false);
和我向下移动可以通过翻译我的画布:
And I'm moving it down by translating my canvas:
canvas.translate(0, getHeight() / 2);
bottomText.draw(canvas);
canvas.restore();
左右;如何将其调整的底部,或者把它拆分成?行数
So; how do I align it to the bottom, or get the number of lines it has been split into?
推荐答案
如何 StaticLayout.getLineCount()
?
这篇关于获取行数StaticLayout会分裂成文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!