is Touch MotionEvent In View - Android User Interface

Android examples for User Interface:Touch Event

Description

is Touch MotionEvent In View

Demo Code


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

public class Main {
    public static boolean isTouchInView(MotionEvent ev, View v) {
        int[] vLoc = new int[2];
        v.getLocationOnScreen(vLoc);//from www  . ja v  a2 s  .c  o m
        float motionX = ev.getRawX();
        float motionY = ev.getRawY();
        return motionX >= vLoc[0] && motionX <= (vLoc[0] + v.getWidth())
                && motionY >= vLoc[1]
                && motionY <= (vLoc[1] + v.getHeight());
    }
}

Related Tutorials