天天记录 - Android View坐标getLeft, getRight, getTop, getBottom
来源:互联网 发布:期货交易系统培编程 编辑:程序博客网 时间:2024/05/16 16:20
1 引起疑惑
分析视图invalidate流程的过程中发现view的left, right, top, bottom跟自己理解的不一样,现在想分析一下这几个值具体的含义。
2 理解坐标,位置概念
这里涉及坐标系的概念:
坐标系在二维视图中通过X轴和Y轴两个数字为组合表示某个点的绝对坐标。
例如(30, 100) 通常表示X轴30, Y轴100交叉的一个点
在Android中可以把left相当于X轴值, top相当于Y轴值, 通过这两个值Android系统可以知道视图的绘制起点,在通过Wdith 和 Height 可以得到视图上下左右具体值,就可以在屏幕上绝对位置绘制视图。right 与 bottom计算如下:
right = left + width;
bottom = top + height;
3 相应API
视图左侧位置 view.getLeft()
视图右侧位置 view.getRight()
视图顶部位置 view.getTop();
视图底部位置 view.getBottom();
视图宽度 view.getWidth();
视图高度 view.getHeight()
4 实例分析
按照我的理解:
蓝色区域位置 left = 0, top = 0 坐标(0, 0 )
黄色区域位置 left = 60, top = 115 坐标(60, 115)
绿色区域位置 left = 115, top = 170 坐标(115, 170)
绿色区域,这里理解错误,我认为绿色区域的位置是针对于蓝色区域的(0, 0)坐标的值,从上图的右下角打印出的坐标值就可以看出与下方我列出的值不一致,看看下面的图就明白了
总结: 视图的left , top , right , bottom 的值是针对其父视图的相对位置, 绿色区域是针对其父视图(即黄色区域为(0, 0)点)的坐标,不应该是(115, 170 ) 而是 (55, 55)
- 天天记录 - Android View坐标getLeft, getRight, getTop, getBottom
- 天天记录 - Android View坐标getLeft, getRight, getTop, getBottom
- Android View坐标getLeft, getRight, getTop, getBottom
- Android View坐标getLeft, getRight, getTop, getBottom
- Android View坐标getLeft, getRight, getTop, getBottom
- Android View坐标getLeft, getRight, getTop, getBottom
- Android View坐标getLeft, getRight, getTop, getBottom
- Android View坐标getLeft, getRight, getTop, getBottom
- Android View坐标getLeft, getRight, getTop, getBottom
- Android View坐标getLeft, getRight, getTop, getBottom
- Android View坐标getLeft, getRight, getTop, getBottom
- Android View坐标getLeft, getRight, getTop, getBottom
- Android View坐标getLeft, getRight, getTop, getBottom
- 天天记录 - Android View坐标getLeft, getRight, getTop, getBotto
- Android View坐标getLeft, getRight, getTop, getBottom解惑
- Android View坐标getLeft, getRight, getTop, getBottom解惑
- Android View坐标getLeft, getRight, getTop, getBottom解惑
- Android View坐标getLeft, getRight, getTop, getBottom解惑
- Hibernate反向工程
- optparse模块代码分析
- 计算程序运行时间
- 全国耳鼻喉科 医院排名
- Windows Xp 远程登录Mysql 数据库设置
- 天天记录 - Android View坐标getLeft, getRight, getTop, getBottom
- 建立OpenFire项目 svn check out 方法
- 绿色版本Tomcat
- makefile实例
- 怎样自动生成makefile
- 使用MD5数据加密
- 编译 boost 1.46 with vc2010
- 关于android的ycbcr_422_i
- Android开发学习笔记(三)Android应用界面编程 Toast/SubMenu学习