Android get ListView, GridView and other scrolling distance (height)

Source: Internet
Author: User

 Public int getscrolly () {    = mlistview.getchildat (0);     if NULL ) {        return 0;    }     int firstvisibleposition = mlistview.getfirstvisibleposition ();     int top = c.gettop ();     return -top + firstvisibleposition * c.getheight ();}

The principle is to assume that the height of each item is certain (it is true in most cases), so you can calculate the total height as long as you know what item is currently on, because part of the first visible item may have moved out of the boundary, somListView.getChildAt(0)获得第一个子view,使用getTop()方法计算出这个偏差。综合起来就可以计算出当前ListView的滚动高度。

Android get ListView, GridView and other scrolling distance (height)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.