Android获得控件在屏幕中的绝对坐标
来源:互联网 发布:文玩属于哪个淘宝类目 编辑:程序博客网 时间:2024/05/24 00:03
int[] location = new int[2] ;view.getLocationInWindow(location); //获取在当前窗口内的绝对坐标view.getLocationOnScreen(location);//获取在整个屏幕内的绝对坐标location [0]--->x坐标,location [1]--->y坐标
getLocationOnScreen
计算该视图在全局坐标系中的x,y值,(注意这个值是要从屏幕顶端算起,也就是索包括了通知栏的高度)//获取在当前屏幕内的绝对坐标
getLocationInWindow
计算该视图在它所在的widnow的坐标x,y值,获取在整个窗口内的绝对坐标
getLeft , getTop, getBottom,getRight
这一组是获取相对在它父亲里的坐标
如果在Activity的OnCreate()
事件输出那些参数,是全为0,要等UI控件都加载完了才能获取到这些。
在onWindowFocusChanged(boolean hasFocus)
中获取为好
即覆写Activity的onWindowFocusChanged(boolean hasFocus)
方法 XXX_Activity:
@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); int[] location1 = new int[2] ; view.getLocationInWindow(location1); //获取在当前窗口内的绝对坐标 int[] location2 = new int[2] ; view.getLocationOnScreen(location2);//获取在整个屏幕内的绝对坐标 //do something }
更多资料:
Android View各种尺寸位置相关的方法探究
PS:本文为转载,首发地址不可考,网上搜到的全是转载的,故不能贴出原地址,如果你是作者可以留言原地址或者要求删除。
0 0
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- Android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- Android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- android获得控件在屏幕中的绝对坐标 getLocationInWindow 和 getLocationOnScreen
- 【cocos2d-x从c++到js】09:JS与C++的交互1——JS代码调用C++代码
- Mac OS上Java环境变量的配置
- android控件属性
- b/s常见漏洞
- 虚拟机中linux系统硬盘扩容(仅供参考)
- Android获得控件在屏幕中的绝对坐标
- MAT分析内存泄漏
- linux服务器上定时备份 mysql 数据库
- Android中的Notification直接实例化方法deprecated的解决
- 成绩排名
- 海量数据搜索、查询
- com.edb.util.PSQLException: FATAL: role "主机名" does not exist
- Hibernate技术应用随笔--关联关系建立
- HTML笔记(1)