is View Contains a point - Android User Interface

Android examples for User Interface:View Contains

Description

is View Contains a point

Demo Code


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

public class Main {
    public static boolean isViewContains(View parentView, View view,
            int rx, int ry) {
        int[] l = new int[2];
        view.getLocationOnScreen(l);/*  w w  w.j a v  a 2  s  .  com*/
        int x = l[0];
        int y = l[1];
        parentView.getLocationOnScreen(l);
        x -= l[0];
        y -= l[1];
        int w = view.getWidth();
        int h = view.getHeight();
        if (rx < x || rx > x + w || ry < y || ry > y + h) {
            return false;
        }
        return true;
    }
}

Related Tutorials