android textview分页,android – 如何翻页长文本?

我有一个很长的文本和固定大小的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 |

所以最后的行数不仅仅是计算.所以我的页面管理员是愚蠢的.有人会帮助我吗?谢谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值