is View Contained a position - Android User Interface

Android examples for User Interface:View Position

Description

is View Contained a position

Demo Code


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

public class Main {
    public static boolean isViewContained(View view, float rawX, float rawY) {
        Log.i("ViewUtil", "isViewContained");
        if (view == null || view.getWidth() == 0) {
            return false;
        }/*from w  w  w . j a v a2s.c  o  m*/

        int[] location = new int[2];
        view.getLocationOnScreen(location);
        int x = location[0];
        int y = location[1];
        Log.i("ViewUtil", "loc of view is: x:" + x + " y:" + y);
        int width = view.getWidth();
        int height = view.getHeight();

        if (rawX < x || rawX > x + width || rawY < y || rawY > y + height) {
            return false;
        } else {
            return true;
        }
    }
}

Related Tutorials