Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.