Android View坐标getLeft, getRight, getTop, getBottom解惑
来源:互联网 发布:斯芬克 知乎 编辑:程序博客网 时间:2024/05/21 05:41
原文地址:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2013/0412/1156.html
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, 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
- Linux下设置发邮件
- extract用法
- 线程等待的几种方式
- iOS 开发之 菜单栏UITabBarController
- 删除表空间报错ORA-00604&ORA-02429解决过程
- Android View坐标getLeft, getRight, getTop, getBottom解惑
- android intent
- 播放视频VideoView和SurfaceView(它是父类)(查看api)(更高级的查看vitamio)
- STL 中的 std::string大小写转换 lowercase、uppercase、Trim、replace、split
- Android 多媒体应用:视频播放之VideoView与SurfaceView
- uva 815
- 【HEOI2014】【BZOJ3613】南园满地堆轻絮
- jquery处理html格式的数据
- android 获取系统时间