Android判断view是否被隐藏
16lz
2023-05-28
/** * 判断view是否被隐藏(如scrollview中被滑动到不可见位置的view) */ public static boolean isViewCovered(final View view) { View currentView = view; Rect currentViewRect = new Rect(); boolean partVisible = currentView.getGlobalVisibleRect(currentViewRect); boolean totalHeightVisible = (currentViewRect.bottom - currentViewRect.top) >= currentView.getMeasuredHeight(); boolean totalWidthVisible = (currentViewRect.right - currentViewRect.left) >= currentView.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; }
更多相关文章
- SlidingMenu和ActionBarSherlock结合做出出色的App布局,Facebook
- linearLayout 和 relativeLayout的属性区别
- Android解决父控件拦截子控件手势滑动事件的问题
- 调出软键盘 挤掉标题栏咋办
- 固定屏幕显示模式 ScreenOrientation
- ListView美化
- Android横向智能刷新框架-SmartRefreshHorizontal+ScrollView 实
- Android全屏(包含3种隐藏顶部状态栏及标题栏和一种隐藏Android(安
- android 仿写 screen lock