View v.getX(), MotionEvent event.getX() 获取坐标区别
2015-02-08 16:00
363 查看
首先明确一下 android中的坐标系统 :屏幕的左上角是坐标系统原点(0,0),原点向右延伸是X轴正方向,原点向下延伸是Y轴正方向。
一、View的坐标
需要注意view的坐标是相对父容器而言的,包括:getTop()、getBottom(),getLeft(),getRight()。以getTop为例,函数源代码为:
/**
* Top position of this view relative to its parent.
*相对应父控件的top位置,单位为像素,即头部到父控件的距离
* @return The top of this view, in pixels.
*/
@ViewDebug.CapturedViewProperty
public final int getTop() {
return mTop;
}
图示1:
![](https://oscdn.geek-share.com/Uploads/Images/Content/201502/ba33e8cdbbe7c60d45f80117662c3238)
![](http://blog.csdn.net/wangjinyu501/article/details/21827341/file:/C:/Users/ADMINI%7E1/AppData/Local/Temp/enhtmlclip/Image.png)
图示2:
![](https://oscdn.geek-share.com/Uploads/Images/Content/201502/c5157ba30be02e0d677176f2ecbaf766)
1、视图左侧位置 view.getLeft()
2、视图右侧位置 view.getRight()
3、视图顶部位置 view.getTop();
4、视图底部位置 view.getBottom();
5、 视图宽度 view.getWidth();
6、视图高度 view.getHeight()
二、MotionEvent类中 getRowX()和 getX()
1、event.getRowX():触摸点相对于屏幕原点的x坐标
2、event.getX(): 触摸点相对于其所在组件原点的x坐标
图示
![](https://oscdn.geek-share.com/Uploads/Images/Content/201502/c8a271f6c08a357b9b12672fb54006b8)
转载处:http://www.sjsjw.com/kf_mobile/article/030724ABA015668.asp
自己再总结下: view 表示获取与父容器之间的距离
MotionEvent 就分为2种: 第一种 触摸点相对于其所在组件原点的e.getY()坐标 第二种触摸点相对于屏幕原点的e.getRowY()坐标,getX()和getY()获得的永远是相对view的触摸位置坐标(这两个值不会超过view的长度和宽度)。
一、View的坐标
需要注意view的坐标是相对父容器而言的,包括:getTop()、getBottom(),getLeft(),getRight()。以getTop为例,函数源代码为:
/**
* Top position of this view relative to its parent.
*相对应父控件的top位置,单位为像素,即头部到父控件的距离
* @return The top of this view, in pixels.
*/
@ViewDebug.CapturedViewProperty
public final int getTop() {
return mTop;
}
图示1:
![](http://blog.csdn.net/wangjinyu501/article/details/21827341/file:/C:/Users/ADMINI%7E1/AppData/Local/Temp/enhtmlclip/Image.png)
图示2:
1、视图左侧位置 view.getLeft()
2、视图右侧位置 view.getRight()
3、视图顶部位置 view.getTop();
4、视图底部位置 view.getBottom();
5、 视图宽度 view.getWidth();
6、视图高度 view.getHeight()
二、MotionEvent类中 getRowX()和 getX()
1、event.getRowX():触摸点相对于屏幕原点的x坐标
2、event.getX(): 触摸点相对于其所在组件原点的x坐标
图示
转载处:http://www.sjsjw.com/kf_mobile/article/030724ABA015668.asp
自己再总结下: view 表示获取与父容器之间的距离
MotionEvent 就分为2种: 第一种 触摸点相对于其所在组件原点的e.getY()坐标 第二种触摸点相对于屏幕原点的e.getRowY()坐标,getX()和getY()获得的永远是相对view的触摸位置坐标(这两个值不会超过view的长度和宽度)。
相关文章推荐
- MOTIONEVENT的GETX()和GETRAWX()和VIEW的GETLEFT()3个方法的区别
- Android MotionEvent 获取View坐标信息
- Android群英传——第五章常用触控事件MotionEvent与获取View坐标长度的各种方法
- 【Android】【自定义View】MotionEvent getX()和getRawX()的区别
- android MotionEvent中getX()和getRawX()的区别
- android MotionEvent中getX()和getRawX()的区别
- android MotionEvent中getX()和getRawX()的区别 .
- MotionEvent中getX()和getRawX()的区别
- Android MotionEvent 坐标获取
- MotionEvent getX()和getRawX()的区别。
- MotionEvent中getX()和getRawX()的区别
- MotionEvent中getX()和getRawX()的区别
- 【MotionEvent】亲测MotionEvent中getX()和getRawX()的区别
- MotionEvent的getX(),getY()与getRawX(),getRawY()区别
- MotionEvent的getX(),getY()与getRawX(),getRawY()区别
- Android MotionEvent中getX()和getRawX()的区别
- MotionEventJ的getX()与getRawX()的区别
- Android MotionEvent 坐标获取
- MotionEvent的getX(),getY()与getRawX(),getRawY()区别
- (转)MotionEvent中getX()和getRawX()的区别