TextPaint mTextPaint=new TextPaint();
mTextPaint.setTextSize(16);
StaticLayout mTextLayout = new StaticLayout(newText, mTextPaint, canvas.getWidth() - 20, Alignment.ALIGN_NORMAL, 1.5f, 0.0f, false);
canvas.save();
int x = 10, y = 50;
y += p.ascent() + p.descent();
canvas.translate(x, y);
mTextLayout.draw(canvas);
canvas.restore();
答案 0 :(得分:2)
首先,您需要获得最后一条可见线。您可以使用Layout.getLineForVertical方法获取它。 之后,您可以使用方法Layout.getLineEnd / Layout.getLineVisibleEnd
获取行的文本偏移量。示例:
int line = mTextLayout.getLineForVertical(canvas.getHeight()); // position of last visible line
int chars = mTextLayout.getLineEnd(line);