首先明确一下 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:
图示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坐标图示
一、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:
图示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坐标图示
本文详细介绍了Android中的坐标系统,包括视图(View)的坐标及其获取方法如getTop(), getBottom(), getLeft(), getRight()等,同时阐述了MotionEvent类中getRowX()和getX()的区别,帮助开发者更好地理解触摸事件的位置信息。
坐标系统&spm=1001.2101.3001.5002&articleId=52535356&d=1&t=3&u=ace4d49106ef4a5bb93cf0ae5a39147e)
1428

被折叠的 条评论
为什么被折叠?



