有没有检索一个TextView的可见行数或范围的一种方式? [英] Is there a way of retrieving a TextView's visible line count or range?

查看:114
本文介绍了有没有检索一个TextView的可见行数或范围的一种方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个全屏幕的TextView持着跨区,需要滚动。该TextView中的getLineCount()给我用于整个文本块行的总数,但我想知道的文本多少行是目前屏幕上可见。

I have a full-screen TextView holding a long Spanned that requires scrolling. The TextView's getLineCount() gives me the total number of lines used for the entire block of text but I'd like to know how many lines of text are currently visible on the screen.

或者,更好的是,有没有办法找出线在屏幕上当前可见的范围内?例如,作为视图卷轴,我可以告诉大家,行20-60当前可见的?

Or, better yet, is there a way to figure out the range of lines currently visible on the screen? For example, as the view scrolls, can I tell that lines 20-60 are currently visible?

推荐答案

我想出了答案:

int height    = myTextView.getHeight();
int scrollY   = myTextView.getScrollY();
Layout layout = myTextView.getLayout();

int firstVisibleLineNumber = layout.getLineForVertical(scrollY);
int lastVisibleLineNumber  = layout.getLineForVertical(scrollY+height);

这篇关于有没有检索一个TextView的可见行数或范围的一种方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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