我有一个很长的文本和固定大小的textView.如何逐页显示文本?用户将以这种方式与程序交互:
他向左或向右滑动以转到下一页或上一页.
目前,我创建了一个PageManager来完成这项工作.但它非常有限.处理文本的核心代码是:
while (true) {
newLineIndex = TextUtils.indexOf(content, '
', processIndex);
if (newLineIndex == -1) {// till the end of content
charCount = paint.breakText(content, processIndex, content.length(), false, leftLines * lineWidth, width);
} else {
charCount = paint.breakText(content, processIndex, ++newLineIndex, false, leftLines * lineWidth, width);
}
leftLines = (int) ((leftLines * lineWidth - width[0]) / lineWidth);
processIndex += charCount;
if (leftLines < 1 || processIndex >= content.length()) {
page = new Page();
page.endIndex = processIndex;
page.startIndex = pageBaseLine;
page.content = content.subSequence(page.startIndex, page.endIndex);
result.add(page);
pageBaseLine = processIndex;
leftLines = lineNumber;
}
if (processIndex >= content.length()) {
break;
}
}
限制是页面可能截断文本
|A lon|
|g wor|
|d man|
//一个长话的人
或由于自动换行而产生的线条:
//页面管理器计算这个(2行):
|a sentence with loooooooo|
|ooong word abcdefghijklmn|
//但实际上是在文本视图中(3行):
|a sentence with |
|looooooooooong word |
|abcdefghijklmn |
所以最后的行数不仅仅是计算.所以我的页面管理员是愚蠢的.有人会帮助我吗?谢谢!