2013-02-23 33 views
0

我正在將一些文本繪製到畫布上,並使用StaticLayout將文本包裹在屏幕上。我想對齊文本,以便文本的底部位於屏幕的底部。獲取行數StaticLayout將文本拆分爲

爲此,我需要知道StaticLayout將文本包裝成多少行,所以我可以將其乘以字體大小,並將其從我的組件的高度偏移很多。

這是我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); 

而且我向下移動可以通過翻譯我的畫布:

canvas.translate(0, getHeight()/2); 
bottomText.draw(canvas); 
canvas.restore(); 

左右;我如何將它與底部對齊,或者獲取它被分割的行數?

回答

4

StaticLayout.getLineCount()怎麼樣?