public static final Rect getViewportBounds ( ) { return new Rect ( Window . getScrollLeft ( ) , Window . getScrollTop ( ) , Window . getClientWidth ( ) , Window . getClientHeight ( ) ) ; }
This takes into account scrolling and will be in absolute coordinates where the top left corner of the page is 0 0 but the viewport may be scrolled to something else .