判断视图是否完整可见
来源:互联网 发布:淘宝上的天天特价好吗 编辑:程序博客网 时间:2024/05/04 06:32
知识点:
From the JavaDoc of getGlobalVisibleRect:
/** * If some part of this view is not clipped by any of its parents, then * return that area in r in global (root) coordinates. To convert r to local * coordinates (without taking possible View rotations into account), offset * it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)). * If the view is completely clipped or translated out, return false. * * @param r If true is returned, r holds the global coordinates of the * visible portion of this view. * @param globalOffset If true is returned, globalOffset holds the dx,dy * between this view and its root. globalOffet may be null. * @return true if r is non-empty (i.e. part of the view is visible at the * root level. */
getLocalVisibleRect calls getGlobalVisibleRect and then makes it local as suggested:
r.offset(-offset.x, -offset.y); // make r local`
So:
- It doesn't return a Rectangle, it returns a boolean. But it can set the parameters of a rectangle you pass, and that must be an android.graphics.Rect rectangle;
- The rectangle r will be filled with local coordinates;
- I'm not sure but I think it's the same for visibile and invisible views, while it should return false for views with
visibility="gone"
详见http://www.myexception.cn/android/1884660.html
private boolean isViewCompletelyVisible(View view) { Rect scrollBounds = new Rect(); mRecyclerView.getHitRect(scrollBounds); if (view.getLocalVisibleRect(scrollBounds)) { //此控件至少有一个像素在可视范围内 Rect rect = new Rect(); view.getGlobalVisibleRect(rect); if (YoukuUtil.isPad()) { if (view.getHeight() <= (rect.bottom - rect.top) && (rect.top >= 0 && rect.top < YoukuUtil.getScreenRealWidth(getActivity().getApplicationContext())) && (rect.bottom > 0 && rect.bottom <= YoukuUtil.getScreenRealWidth(getActivity().getApplicationContext()))) { return true; } } else { if (view.getHeight() <= (rect.bottom - rect.top) && (rect.top >= 0 && rect.top < YoukuUtil.getScreenRealHeight(getActivity().getApplicationContext())) && (rect.bottom > 0 && rect.bottom <= YoukuUtil.getScreenRealHeight(getActivity().getApplicationContext()))) { return true; } } } return false;}
0 0
- 判断视图是否完整可见
- 判断view是否可见
- 判断view是否可见
- 判断当前fragment是否可见
- 判断物体摄像机是否可见
- Fragment判断页面是否可见
- View是否可见状态判断
- 如何判断Fragment是否可见
- android 视图(View)是否可见状态
- 判断scrollview中某子控件是否可见
- 判断 Fragment 的 UI 是否可见
- 判断Fragment是否可见,填坑
- 如何判断Fragment是否对用户可见
- 判断当前ViewPager中Fragment是否可见
- 如何判断Fragment是否对用户可见
- 如何判断当前的Fragment是否可见?Fragment的可见与不可见的判断方法。
- Java判断文件是否完整
- android 判断控件是否在屏幕范围内 是否可见
- Leetcode 226. Invert Binary Tree
- iOS 环信集成方法之注册环信账号
- iOS开发 上拉查看图片详情实现思路
- leetcode 226. Invert Binary Tree
- axure
- 判断视图是否完整可见
- Linux操作系统的简单指令(pwd、ls、cd、su、whoami、init、which、cat、clear等)
- 查看Centos的iP,ifconfig执行之后eth0没有ip地址的解决办法
- Vitamio视频在小米5手机无法播放问题
- 图片资料
- iOS学习之——图片相关
- 第十三周-阅读程序
- newLisp使用初步
- 在线文档预览方案-office web apps