Created
May 15, 2020 11:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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