get View Bounds - Android User Interface

Android examples for User Interface:View Property

Description

get View Bounds

Demo Code


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

public class Main {
    public static Rect getBounds(View view) {
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        int width = view.getWidth();
        int height = view.getHeight();
        return new Rect(location[0], location[1], location[0] + width,
                location[1] + height);/*from  w  w  w .  j  a  v a 2s .  c  o m*/
    }
}

Related Tutorials