首页 > 其他 > 详细

判断最后listView中最后一个item是否完全显示出来

时间:2015-03-03 18:26:22      阅读:387      评论:0      收藏:0      [点我收藏+]
 /**
     * 判断最后listView中最后一个item是否完全显示出来
     * listView 是集合的那个ListView
     * @return true完全显示出来,否则false
     */
    
    protected boolean isLastItemVisible() {
        final Adapter adapter1 = listView.getAdapter();

        if (null == adapter || adapter.isEmpty()) {
            return true;
        }

        final int lastItemPosition = adapter.getCount() - 1;
        final int lastVisiblePosition = listView.getLastVisiblePosition();

        /**
         * This check should really just be: lastVisiblePosition == lastItemPosition, but ListView
         * internally uses a FooterView which messes the positions up. For me we‘ll just subtract
         * one to account for it and rely on the inner condition which checks getBottom().
         */
        if (lastVisiblePosition >= lastItemPosition - 1) {
            final int childIndex = lastVisiblePosition - listView.getFirstVisiblePosition();
            final int childCount = listView.getChildCount();
            final int index = Math.min(childIndex, childCount - 1);
            final View lastVisibleChild = listView.getChildAt(index);
            if (lastVisibleChild != null) {
                return lastVisibleChild.getBottom() <= listView.getBottom();
            }
        }

        return false;
    }

 

判断最后listView中最后一个item是否完全显示出来

原文:http://www.cnblogs.com/jss4j/p/4311602.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!