Is touch Event In View - Android User Interface

Android examples for User Interface:Touch Event

Description

Is touch Event In View

Demo Code


//package com.java2s;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;

public class Main {
    public static boolean touchEventInView(View view, MotionEvent ev) {
        int[] loc = new int[2];
        Rect rect;/*from w ww .java  2  s  .co m*/

        view.getLocationInWindow(loc);
        rect = new Rect(0, 0, view.getWidth(), view.getHeight());
        rect.offsetTo(loc[0], loc[1]);

        return rect.contains(round(ev.getRawX()), round(ev.getRawY()));
    }

    private static int round(float f) {
        return Math.round(f);
    }
}

Related Tutorials