在 textview 中获取当前可见文本 [英] Get current visible text in textview

查看:22
本文介绍了在 textview 中获取当前可见文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个被 ScrollView 包裹的 TextView 中有一个很长的段落.有没有办法找到当前可见的文字?

I have a long passage in a TextView which is wrapped around by ScrollView. Is there any way to find the current visible text?

我可以在 textview 中找到行数、行高,还可以从 scrollview 中找到 scrollx 和 scrolly,但可以找到与当前显示文本的链接.请帮忙!谢谢.

I can find the number of lines, line height in textview and also scrollx and scrolly from scrollview, but find the linkage to the current displayed text. Please help! Thanks.

推荐答案

这样做很简单:

int start = textView.getLayout().getLineStart(0);
int end = textView.getLayout().getLineEnd(textView.getLineCount() - 1);

String displayed = textView.getText().toString().substring(start, end);

这篇关于在 textview 中获取当前可见文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆