我正在画布上绘制一些文本,并使用 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();
所以; 如何将其与底部对齐,或获取已拆分的行数?