【问题标题】:Get number of lines StaticLayout will split text into获取行数StaticLayout将文本分割成
【发布时间】:2013-04-23 00:09:38
【问题描述】:

我正在画布上绘制一些文本,并使用 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();

所以;如何将其与底部对齐,或获取已拆分的行数?

【问题讨论】:

    标签: android layout android-canvas


    【解决方案1】:

    StaticLayout.getLineCount()怎么样?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-17
      • 2010-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多