Android controls retrieved by coordinates
/*** Obtain the corresponding child Control Based on coordinates
* Use ** @ param x coordinate * @ param y coordinate * @ return destination View */public View getViewAtActivity (int x, int y) in the Activity) {// obtain the container View root = getWindow () from the Activity (). getDecorView (); return findViewByXY (root, x, y);}/*** obtain the corresponding child Control Based on coordinates
* Use ** @ param x coordinate * @ param y coordinate * @ return target View */public View getViewAtViewGroup (int x, int y) {return findViewByXY (this, x, y);} private View findViewByXY (View view, int x, int y) {View targetView = null; if (view instanceof ViewGroup) {// parent container, traverse the sub-control ViewGroup v = (ViewGroup) view; for (int I = 0; I <v. getChildCount (); I ++) {targetView = findViewByXY (v. getChildAt (I), x, y); if (targetView ! = Null) {break ;}}else {targetView = getTouchTarget (view, x, y) ;}return targetView;} private View getTouchTarget (View view, int x, int y) {View targetView = null; // determines whether a view can focus on the ArrayList.
TouchableViews = view. getTouchables (); for (View child: TouchableViews) {if (isTouchPointInView (child, x, y) {targetView = child; break ;}} return targetView ;} private boolean isTouchPointInView (View view, int x, int y) {int [] location = new int [2]; view. getLocationOnScreen (location); int left = location [0]; int top = location [1]; int right = left + view. getMeasuredWidth (); int bottom = top + view. getMeasuredHeight (); if (view. isClickable () & y> = top & y <= bottom & x> = left & x <= right) {return true;} return false ;}