tags:

views:

60

answers:

1

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.

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?

+1  A: 

I figured out the answer:

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

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