Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.graphics.Rect;
import android.view.View;

import android.widget.ListView;

public class Main {
    private static final int VISIBLE_SLOP = 30;

    /**
     * to judge whether items take full page
     * if not ,even if last item is visible ,we should not call listener
     *
     * @return whether items take up full page
     */
    public static boolean itemTakeFullPage(ListView list) {
        if (list.getChildCount() > 0) {
            int totalHeight = 0;
            for (int i = 0; i < list.getChildCount(); i++) {
                View child = list.getChildAt(i);
                Rect childRect = new Rect();
                child.getDrawingRect(childRect);
                totalHeight += childRect.height();
            }
            Rect visibleRect = new Rect();
            list.getGlobalVisibleRect(visibleRect);
            return (visibleRect.bottom - visibleRect.top) - totalHeight < VISIBLE_SLOP;
        }
        return false;
    }
}