get Window Rect On Screen - Android User Interface

Android examples for User Interface:Window

Description

get Window Rect On Screen

Demo Code


//package com.java2s;

import android.view.View;

import android.view.Window;

public class Main {
    /**/* www  .j  a  v  a  2s  .c o m*/
     * @returns {x0,y0,x1,y1}
     */
    private static void getWindowRectOnScreen(Window window,
            int rect[/* 4 */]) {
        View decorView = window.getDecorView();
        decorView.getLocationOnScreen(rect); // into rect[0], rect[1]
        rect[2] = rect[0] + decorView.getMeasuredWidth(); // x1 = x0 + width
        rect[3] = rect[1] + decorView.getMeasuredHeight(); // y1 = y0 + height
    }
}

Related Tutorials