Is there a way of retrieving a TextView's visible line count or range?

前端 未结 2 1075
无人及你
无人及你 2020-12-05 03:14

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

2条回答
  •  既然无缘
    2020-12-05 03:49

    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);
    

提交回复
热议问题