转自:http://blog.csdn.net/lwklan/article/details/50588916
方法一:
/**
* 判断触摸的点是否在EditText范围内
*/
private boolean isInEditText(View v, MotionEvent event) {
Rect frame = new Rect();
v.getHitRect(frame);
float eventX = event.getX();
float eventY = event.getY();
return frame.contains((int) eventX, (int) eventY);
}
方法二:
/**
* 判断触摸的点是否在EditText范围内
*/
private boolean isInEditText2(View v, MotionEvent event) {
int[] l = { 0, 0 };
v.getLocationInWindow(l);
int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left + v.getWidth();
float eventX = event.getX();
float eventY = event.getY();
Rect rect = new Rect(left, top, right, bottom);
return rect.contains((int) eventX, (int) eventY);
}