Android 判断View是否被遮挡
来源:互联网 发布:重庆行知教育集团 编辑:程序博客网 时间:2024/04/30 15:46
android开发中,我经常会遇到View是否被覆盖的问题,那么,要如何来判断一个View是否被遮挡呢?
原理,通过view的四个顶点坐标,判断view之间是否有重叠的区域,以此来判断view是否被遮挡,但是情况覆盖不全面,需要根据具体情况调整判断策略
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;}
0 0
- android 判断view 是否被遮挡
- Android 判断view是否被遮挡
- Android 判断View是否被遮挡
- Android多层级判断view是否被遮挡
- 两种Android判断view是否部分被遮挡(或者移出屏幕)的方法
- Android判断view是否部分被遮挡(或者移出屏幕)的方法
- 判断一个窗体是否被完全遮挡
- VC中判断指定窗口是否被其他窗口遮挡
- 判断窗口是否被完全遮挡的方法
- Android判断当前View是否被覆盖
- Android View遮挡问题解决方案
- Android动画被父View遮挡的解决办法
- android view放大被遮挡,我来解决
- 判断view是否显示
- 判断view是否可见
- 判断view是否可见
- android 判断 某个点是否在View的区域内
- 遮挡判断
- Android 中Toast工具类
- Android--Demo_PullToRefresh(基础篇)
- asp.net Framework 与 asp.net core 知识
- 使用pl/sql来调用java
- 【iOS开发】Foreign famous blogs
- Android 判断View是否被遮挡
- 第14周项目 2—数组类模板
- 在raspberry运行xibo
- weblogic解决Jar包冲突
- LeetCode-155.Min Stack
- 论big data 3.0取代SAP HANA的可行性
- 大数据Kafka
- C++ eof()函数相关应用技巧分享
- getCacheDir()、getFilesDir()、getExternalFilesDir()