本文实例讲述了Android判断touch事件点是否在view范围内的方法。分享给大家供大家参考,具体如下:
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程序设计有所帮助。
【Android判断touch事件点是否在view范围内的方法】相关文章:
★ Android开发笔记之:在ImageView上绘制圆环的实现方法
★ Android解决dialog弹出时无法捕捉Activity的back事件的方法