Java tutorial
//package com.java2s; import android.graphics.Rect; import android.view.MotionEvent; import android.view.View; public class Main { /** * <pre> * Determine whether a {@link MotionEvent} is on a {@link View} * </pre> */ public static boolean motionEventOnView(MotionEvent event, View view) { int[] location = new int[2]; view.getLocationOnScreen(location); int x = location[0]; int y = location[1]; int w = view.getWidth(); int h = view.getHeight(); Rect rect = new Rect(x, y, x + w, y + h); return rect.contains((int) event.getRawX(), (int) event.getRawY()); } }