Android View坐标getLeft, getRight, getTop, getBottom解惑
来源:互联网 发布:python高手之路 第3版 编辑:程序博客网 时间:2024/05/21 02:33
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)坐标的值,从上图的右下角打印出的坐标值就可以看出与下方我列出的值不一致,看看下面的图就明白了
原文地址:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2013/0412/1156.html
- 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, 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
- Algorithms Every Data Scientist Should Know: Reservoir Sampling
- Java三大框架之spring aop 配置错误一
- TCP长连接和短连接
- 12、Struts2高级技术
- git pull命令更新本地项目的时候遇到“No remote repository specified……”的错误
- Android View坐标getLeft, getRight, getTop, getBottom解惑
- zookeeper伪分布式错误解决:无法创建目录"/opt/beh/logs": 权限不够
- AngularJs是什么?与jQuery有什么不同?
- java基础的练习题
- [Git] error: Your local changes to the following files would be overwritten by merge
- StringBuilder&StringBuffer&String
- Checking Whether a String is Numeric
- 双卡双待 getDeviceId unique device ID IMEI 不唯一 会变问题
- Maven 插件之 maven-antrun-plugin