You can also use Rect.intersect() to find overlapping views.
int[] firstPosition = new int[2];
int[] secondPosition = new int[2];
firstView.getLocationOnScreen(firstPosition);
secondView.getLocationOnScreen(secondPosition);
// Rect constructor parameters: left, top, right, bottom
Rect rectFirstView = new Rect(firstPosition[0], firstPosition[1],
firstPosition[0] + firstView.getMeasuredWidth(), firstPosition[1] + firstView.getMeasuredHeight());
Rect rectSecondView = new Rect(secondPosition[0], secondPosition[1],
secondPosition[0] + secondView.getMeasuredWidth(), secondPosition[1] + secondView.getMeasuredHeight());
return rectFirstView.intersect(rectSecondView);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…