android 上视图的手势坐标是什么

发布于 2024-10-07 16:45:11 字数 769 浏览 0 评论 0原文

当使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如歌彻婉言 2024-10-14 16:45:11

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文