android 上视图的手势坐标是什么
当使用 GestureDetector 捕获屏幕上的手势时,我对 Android 的屏幕 XY 坐标感到困惑。例如:
class TouchPadGL extends GestureDetector.SimpleOnGestureListener {
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
Log.i("onScroll",String.format("dsX: %s, dsY: %s",distanceX,distanceY));
}
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
Log.i("onFling",String.format("vX: %s, vY: %s",velocityX,velocityY));
}
}
根据上面 onScroll 方法的输出,看起来点 (0,0) 位于视图的右下角,X 轴向左拉伸,Y 轴向上拉伸。但是当检查onFling方法的输出时,你会发现左上角似乎是(0,0),并且X轴向右拉伸,Y轴向下拉伸。为什么会发生这种事?
是 android api 中的错误还是我理解错了?
顺便说一句,代码在 API 2.1 上运行
When using GestureDetector to capture gesture on screen, I'm confused by android's screen X-Y coordinate. For example:
class TouchPadGL extends GestureDetector.SimpleOnGestureListener {
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
Log.i("onScroll",String.format("dsX: %s, dsY: %s",distanceX,distanceY));
}
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
Log.i("onFling",String.format("vX: %s, vY: %s",velocityX,velocityY));
}
}
According to output of the above onScroll method, it's seemed the point (0,0) is at the right-down corner of the view, with the X-axe stretch to left and Y-axe stretch upward. But when check the output of the onFling method, you will found that it's seemed (0,0) is at the top-left corner and X-axe stretch to right and Y-axe stretch downward. why could that happen ?
Is is a bug in the android api or i take it wrong ?
BTW, the code is run on API 2.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
docs 说:
distanceX 自上次调用 onScroll 以来沿 X 轴滚动的距离。这不是 e1 和 e2 之间的距离。
distanceY 自上次调用 onScroll 以来沿 Y 轴滚动的距离。这不是 e1 和 e2 之间的距离。
the docs say:
distanceX The distance along the X axis that has been scrolled since the last call to onScroll. This is NOT the distance between e1 and e2.
distanceY The distance along the Y axis that has been scrolled since the last call to onScroll. This is NOT the distance between e1 and e2.