public boolean isViewCovered(final View view) {
View currentView = view;
Rect currentViewRect = new Rect();
boolean partVisible = currentView.getGlobalVisibleRect(currentViewRect);
boolean totalHeightVisible = (currentViewRect.bottom - currentViewRect.top) >= view.getMeasuredHeight();
boolean totalWidthVisible = (currentViewRect.right - currentViewRect.left) >= view.getMeasuredWidth();
boolean totalViewVisible = partVisible && totalHeightVisible && totalWidthVisible;
if (!totalViewVisible)//if any part of the view is clipped by any of its parents,return true
return true;
while (currentView.getParent() instanceof ViewGroup) {
ViewGroup currentParent = (ViewGroup) currentView.getParent();
if (currentParent.getVisibility() != View.VISIBLE)//if the parent of view is not visible,return true
return true;
int start = indexOfViewInParent(currentView, currentParent);
for (int i = start + 1; i < currentParent.getChildCount(); i++) {
Rect viewRect = new Rect();
view.getGlobalVisibleRect(viewRect);
View otherView = currentParent.getChildAt(i);
Rect otherViewRect = new Rect();
otherView.getGlobalVisibleRect(otherViewRect);
if (Rect.intersects(viewRect, otherViewRect))//if view intersects its older brother(covered),return true
return true;
}
currentView = currentParent;
}
return false;
}
private int indexOfViewInParent(View view, ViewGroup parent) {
int index;
for (index = 0; index < parent.getChildCount(); index++) {
if (parent.getChildAt(index) == view)
break;
}
return index;
}
android view是否被覆盖
?著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事?!?“怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 我买了第一行代码 android 第二版,按照书中的例子开始学习,第一章没问题,第二章创建项目在给按钮添加事件时报...
- 版权声明:本文为博主原创文章,未经博主允许不得转载。系列教程:Android开发之从零开始系列源码:github....
- 引子 最近有项目开始使用SurfaceView, 这个View跟Android中其他的View有很大的不同, 所以...