get View Bounds as RectF - Android User Interface

Android examples for User Interface:View Property

Description

get View Bounds as RectF

Demo Code


//package com.java2s;
import android.graphics.RectF;

import android.view.View;

public class Main {
    public static RectF getViewBounds(View view) {
        int location[] = new int[2];
        view.getLocationOnScreen(location);
        int viewX = location[0];
        int viewY = location[1];

        return new RectF(viewX, viewY, viewX + view.getWidth(), viewY
                + view.getHeight());/*from ww  w. jav  a2  s.  c  om*/
    }
}

Related Tutorials