ListView determines whether the ListView has reached the bottom and top

Source: Internet
Author: User

ListView determines whether the ListView has reached the bottom and top
The judgment that the ListView has reached the top

            public boolean isListViewReachTopEdge(final ListView listView) {                boolean result=false;                if(listView.getFirstVisiblePosition()==0){                    final View topChildView = listView.getChildAt(0);                    result=topChildView.getTop()==0;                }                return result ;            }

Note:GetTop () of a view indicates the vertical distance from the top of the View to the upper left corner of the parent control. When the getTop () value of the first child View in ListView is zero, it indicates that the ListView has been rolled to the top or cannot be moved up on the top.
The judgment that the ListView has reached the bottom
            public boolean isListViewReachBottomEdge(final ListView listView) {                boolean result=false;                if (listView.getLastVisiblePosition() == (listView.getCount() - 1)) {                    final View bottomChildView = listView.getChildAt(listView.getLastVisiblePosition() - listView.getFirstVisiblePosition());                    result= (listView.getHeight()>=bottomChildView.getBottom());                };                return  result;            }

Note:The getBottom () of the view indicates the vertical distance from the bottom of the View to the upper left corner of the parent control. When the getBottom () of the last child View of the ListView is smaller than or equal to the getHeight () of the ListView, it indicates that the ListView is rolled to the bottom or already at the bottom. You cannot slide down any more. For more information about getLeft, getRight, getTop, and getBottom of View, see getLeft, getRight, getTop, and getBottom of Android View.

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.