smail2133 smail2133 - 1 year ago 164
Android Question

detect if views are overlapping

I have problem with drawing views on another size screens!
I need method which has two parameters of View type. And return true if first view overlapping on second view, and false in another case!

enter image description here


enter image description here

Answer Source

Berserk thanks you for help! After some experiments I wrote method which detect view is overlapped or not for my case!

private boolean isViewOverlapping(View firstView, View secondView) {
        int[] firstPosition = new int[2];
        int[] secondPosition = new int[2];

        firstView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);

        int r = firstView.getMeasuredWidth() + firstPosition[0];
        int l = secondPosition[0];
        return r >= l && (r != 0 && l != 0);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download