检测视图是否重叠 [英] detect if views are overlapping
本文介绍了检测视图是否重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在其他尺寸的屏幕上绘制视图时遇到问题!我需要具有两个 View 类型参数的方法.如果第一个视图与第二个视图重叠,则返回 true,在另一种情况下返回 false!
I have problem with drawing views on another size screens! I need method which has two parameters of View type. And return true if first view overlapping on second view, and false in another case!
和
推荐答案
Berserk 感谢您的帮助!经过一些实验,我编写了检测视图是否重叠的方法,适用于我的情况!
Berserk thanks you for help! After some experiments I wrote method which detect view is overlapped or not for my case!
private boolean isViewOverlapping(View firstView, View secondView) {
int[] firstPosition = new int[2];
int[] secondPosition = new int[2];
firstView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
firstView.getLocationOnScreen(firstPosition);
secondView.getLocationOnScreen(secondPosition);
int r = firstView.getMeasuredWidth() + firstPosition[0];
int l = secondPosition[0];
return r >= l && (r != 0 && l != 0);
}
这篇关于检测视图是否重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文