在也响应 onTouchEvent 的视图内处理 onTouchEvent (用于在 OSMdroid 3.0.2 中工作)

发布于 2024-11-26 05:07:29 字数 1372 浏览 1 评论 0原文

我目前使用的是 osmdroid jar 3.0.1,并且我有一个 MapView “可拖动空间”(可以在屏幕之间滑动的视图)。 我在底部有一个栏,可以让用户在空格之间滑动, 如果触摸事件发生在该区域之外,我会调用 mapView.onTouchEvent(事件)。

这曾经在 3.0.1 中运行良好,但我在 osmdroid 3.0.4 中尝试过,它 似乎只适用于垂直运动(我怀疑这与 到一些触摸斜率设置)。

这是我的 Dragable Space 视图中的代码。

@Override
public boolean onTouchEvent(MotionEvent event) {
    // Check if the current space is the Map space and we are over the map
    // difference is the Y value between the top and bottom of the map area.
    if (this.mCurrentScreen == 1
                    && event.getY() >= topY && event.getY() <= difference){
            Log.d(TAG, "touch received inside Map Area");
            // Pass the event directly to the mapView.
            return mOsmv.onTouchEvent(event);
    }
    Log.d(TAG, "touch received outside Map Area");
    return super.onTouchEvent(event);
}

虽然这很令人讨厌(视图必须传递一个实例) 地图),它在 3.0.1 和 3.0.2 版本中运行良好。然而,自从 3.0.3 不再有效。

现在有更好的方法将触摸事件传递到 osmdroid 地图吗?

我有一个演示项目可以说明这个问题。全食 项目在 github 上

您可以更改构建路径以使用 3.0.1 或 3.0.2 jar,地图会在较大空间内正确滚动,但更改为 3.0.3 或 3.0.4 时,任何横向移动都会被忽略。

任何指导将不胜感激。

PS,这是来自 OSMdroid 列表的交叉帖子。我希望这里有更多的读者。

I am currently using osmdroid jar 3.0.1, and I have a MapView inside a
"Dragable Space" (a view that you can swipe between screens).
I have a bar at the bottom that lets the user swipe between the spaces,
and if the touch event occurs outside that area, I call
mapView.onTouchEvent(event).

This used to work well in 3.0.1, but I tried in osmdroid 3.0.4, and it
only appears to work for vertical movement (which I suspect is related
to some touch slop setting).

Here is the code from my Dragable Space view.

@Override
public boolean onTouchEvent(MotionEvent event) {
    // Check if the current space is the Map space and we are over the map
    // difference is the Y value between the top and bottom of the map area.
    if (this.mCurrentScreen == 1
                    && event.getY() >= topY && event.getY() <= difference){
            Log.d(TAG, "touch received inside Map Area");
            // Pass the event directly to the mapView.
            return mOsmv.onTouchEvent(event);
    }
    Log.d(TAG, "touch received outside Map Area");
    return super.onTouchEvent(event);
}

Although this is nasty (the view has to be passed an instance of the
map), it did work fine in versions 3.0.1 and 3.0.2. However, since
3.0.3 it no longer works.

Is there a better way to pass touch events to the osmdroid map now?

I have a demo project that illustrates this problem. The full eclipse
project is on github.

You can change the build path to use a 3.0.1 or 3.0.2 jar, and the map scrolls around correctly inside the larger space, but changing to 3.0.3 or 3.0.4 and any sideways movement is ignored.

Any guidance would be greatly appreciated.

PS, this is a cross post from the OSMdroid list. I hope there are a few more readers here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

轮廓§ 2024-12-03 05:07:29

问题是 MapView.onTouchEvent 在版本 3.0.2 和 3.0.3 之间被重命名为 MapView.dispatchTouchEvent

The problem was that MapView.onTouchEvent was renamed to MapView.dispatchTouchEvent between versions 3.0.2 and 3.0.3

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