本文实例讲述了Android判断touch事件点是否在view范围内的方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
private Rect mChangeImageBackgroundRect = null ;
private boolean isInChangeImageZone(View view, int x, int y) {
if ( null == mChangeImageBackgroundRect) {
mChangeImageBackgroundRect = new Rect();
}
view.getDrawingRect(mChangeImageBackgroundRect);
int [] location = new int [ 2 ];
view.getLocationOnScreen(location);
mChangeImageBackgroundRect.left = location[ 0 ];
mChangeImageBackgroundRect.top = location[ 1 ];
mChangeImageBackgroundRect.right = mChangeImageBackgroundRect.right + location[ 0 ];
mChangeImageBackgroundRect.bottom = mChangeImageBackgroundRect.bottom + location[ 1 ];
return mChangeImageBackgroundRect.contains(x, y);
}
|
其中view是要判断的view ,x,y是Down X, Down Y
希望本文所述对大家Android程序设计有所帮助。