Skip to content

Instantly share code, notes, and snippets.

@bansalayush
Created May 15, 2020 11:39
Show Gist options
  • Save bansalayush/078547456eacf35f76db4f448f073b18 to your computer and use it in GitHub Desktop.
Save bansalayush/078547456eacf35f76db4f448f073b18 to your computer and use it in GitHub Desktop.
Check if the current focus in within a given view or outside of a view
View v = getCurrentFocus(); // get current view in focus
//get x,y coordinates of view
int[] scrcoords = new int[2];
v.getLocationOnScreen(scrcoords);
float x = ev.getRawX() + v.getLeft() - scrcoords[0];
float y = ev.getRawY() + v.getTop() - scrcoords[1];
//check if the touch was outside the current view
if (x < v.getLeft() || x > v.getRight() || y < v.getTop() || y > v.getBottom()) {
// do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment