0

我正在使用 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);
    }

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

4

1 回答 1

1

实际上 mapview 类是 ViewGroup 的扩展类。您应该执行以下操作:

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

于 2013-12-11T19:03:07.980 回答