【发布时间】:2012-12-19 14:46:49
【问题描述】:
我想在TextView 中查看长数据。我正在尝试使用以下代码进行分页:
TextPaint textPaint = tv.getPaint();
int boundedWidth = tv.getWidth();
StaticLayout layout = new StaticLayout(data, textPaint, boundedWidth , Alignment.ALIGN_NORMAL, 1.0f, 1, false);
layout.draw(new Canvas());
int totalLines = layout.getLineCount();
int currentPageNum = 0;
int topLine = 0;
int bottomLine = 0;
topLine = layout.getLineForVertical( currentPageNum * height );
bottomLine = layout.getLineForVertical( (currentPageNum + 1) * height );
int pageOffset = layout.getLineStart(topLine);
int pageEnd = layout.getLineEnd(bottomLine);
tv.setText(data.subSequence(pageOffset, pageEnd));
但是 pageoffset 和 pageend 给我的 startline+1 和 endline+1 值不是应该绘制的文本的确切偏移量。
我的代码有什么问题?还有其他方法吗?
【问题讨论】:
标签: android text pagination textview