Android开发(二十八)——基础功能函数

 

 

/**
 * 判断事件是否在控件中
 * 
 * @param view
 * @param ev
 * @return
 * @see http://m.blog.csdn.net/blog/aygxylxk/8950268
 */
public static boolean inRangeOfView(View view, MotionEvent ev) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int x = location[0];
    int y = location[1];
    if (ev.getRawX() < x || ev.getRawX() > (x + view.getWidth())
            || ev.getRawY() < y || ev.getRawY() > (y + view.getHeight())) {
        return false;
    }
    return true;
}




/**
* 判断是否在view中
* If the motion event was relative to the view * which in ignored view list,return true; * * @param ev * @param v * @return * @see https://github.com/SpecialCyCi/AndroidResideMenu/blob/master/ResideMenu/src/com/special/ResideMenu/ResideMenu.java */ private boolean isInIgnoredView(MotionEvent ev,View v) { Rect rect = new Rect(); v.getGlobalVisibleRect(rect); if (rect.contains((int) ev.getX(), (int) ev.getY())) return true; return false; }

 

posted @ 2015-07-12 15:39  长城的草  阅读(739)  评论(0编辑  收藏  举报