android中View坐标学习

来源:互联网 发布:海马玩模拟器mac版删 编辑:程序博客网 时间:2024/04/28 12:55
分类: android 39人阅读 评论(0)收藏 举报

1、View的坐标

[java] view plaincopyprint?
  1. /** 
  2.  * Top position of this view relative to its parent. 
  3.  *相对应父控件的top位置,单位为像素,即头部到父控件的距离 
  4.  * @return The top of this view, in pixels. 
  5.  */  
  6. @ViewDebug.CapturedViewProperty  
  7. public final int getTop() {  
  8.     return mTop;  
  9. }  

其它的getBottom,getLeft,getRight类似

图例:

2、点击View时MotionEvent的坐标

getRawY:表示相对于屏幕左上角的y坐标值(注意:这个屏幕左上角是手机屏幕左上角,不管activity是否有titleBar或是否全屏幕),

getY:表示相对于View自身左上角的y坐标

图例:

组合图:

 

由上图可知:

View到屏幕上边的距离=e.getRawY-.getY

Item到屏幕上边的距离=e.getRawY-e.getY+item.getTop

等等


原创粉丝点击