【问题标题】:Mapsforge rewrite : Context menu on longpress on MapMapsforge 重写:长按地图上的上下文菜单
【发布时间】:2013-11-30 18:33:43
【问题描述】:

我正在使用 mapsforge 库在我的应用程序中使用地图。我需要启动上下文菜单并返回地图坐标。这是我尝试过的。在我的布局中,我在地图视图下方设置了一个隐藏按钮,用于侦听长按。

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <org.mapsforge.map.android.view.MapView
            android:id="@+id/offlinemapview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

        <Button
            android:id="@+id/mapview_btn_offline"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

然后我将这个按钮注册为上下文菜单并膨胀上下文菜单。

mapb = (Button) findViewById(R.id.mapview_btn_offline);
registerForContextMenu(mapb);

  @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.map_menu, menu);
    }

但是当我运行应用程序时,即使在长按后上下文菜单也不会出现。关于如何使它工作的任何想法?

【问题讨论】:

    标签: android contextmenu openstreetmap long-press


    【解决方案1】:

    其实mapview类是ViewGroup的扩展类。 你应该做到以下几点:

    1.覆盖mapsforge中的OnTouchEvent。 MotionEvent 为您提供一些操作。 2.定义一个定时器来保持touch_down和touch_up之间的时间或取消。 3.如何实施备件由您决定......

    【讨论】:

    • 谢谢,我从 simpleGestureListener 实现了 onLongPress。我现在正在尝试获取长按位置的地图地理坐标。
    • 我们可以给它一个sn-p吗?我也需要这个代码.....我希望 mapsforge 在未来的版本中支持这个
    • mapsforge 的所有三个(救援、重写、稳定)版本现在都支持 longpress。
    猜你喜欢
    • 1970-01-01
    • 2014-05-04
    • 2022-11-13
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多