读书人

onTouch 座标

发布时间: 2012-07-23 09:42:20 作者: rapoo

onTouch 坐标

case MotionEvent.ACTION_MOVE:?
??? NowX = event.getX();
??? break;

?

?

NowX:? 相对于注册监听的控件的 横坐标

?? 如果控件在最左边, NowX 一直大于0? 小于屏幕宽

?

getX是获取以widget左上角为坐标原点计算的X轴坐标直.
getRawX 获取的是以屏幕左上角为坐标原点计算的X轴坐标直.

?

1,public final float getRawX()
Returns the original raw X coordinate of this event. For touch events on the screen, this is the original location of the event on the screen, before it had been adjusted for the containing window and views


2,public final float getX()
Returns the X coordinate of this event. Whole numbers are pixels; the value may have a fraction for input devices that are sub-pixel precise

view看做一个矩形,分别表示的是一个view的左边,上边,右边,下边距离他的父组件的距离。
getRight() =getLeft() + getWidth()。 getBottom()= getTop() + getHeight()

读书人网 >移动开发

热点推荐