创建图形页面具有文本菜单不重叠图形、菜单、文本、页面

2023-09-04 06:34:36 作者:捡你不如捡破烂.

我有一个图形窗口和我想显示一个文本菜单时longclick但到目前为止最接近的解决方案,我发现的是的在这里anddev ,最主要的原因,我不喜欢这种方法,因为任何点击激活文本菜单,而不是长时间点击。

I have a mapview and i wish to display a ContextMenu when longclick but so far the closest solution i've found is here on anddev , the main reason i do not like that method is because any click activate the ContextMenu instead of a long click.

问:

有没有办法来显示地图的文本菜单不使用叠加?为什么呢?

Is there a way to display the ContextMenu of a Map without using Overlays? Why?

推荐答案

这是我使用的方法。我创建了扩展MapActivity了AbstractMap类。在这里,我再从AbstractMap类扩展到创建一个适合我的需求的地图。注意:我只用了这种方法,因为我需要几个地图与我的应用程序不同的属性。你可以简单地从AbstractMap删除摘要关键字,直接覆盖这个类中的OnGestureListener方法和实例化。

This is the approach I used. I created an AbstractMap class which extended MapActivity. From here I then extended from the AbstractMap class to create a Map which suited my requirements. Note I only used this approach since I was requiring several maps with varying properties for my application. You could simply remove the Abstract keyword from the AbstractMap, directly override the OnGestureListener methods within this class and instantiate it.

下面是AbstractMap类

Here is the AbstractMap class

public abstract class AbstractMap extends MapActivity implements OnGestureListener, OnDoubleTapListener {

public MapView mapView;
public MapController mapController;
public List<Overlay> mapOverlays;
private GestureDetector detector;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.mapp);
        detector = new GestureDetector(this, this);
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setOnTouchListener(otl);
        mapController = mapView.getController();
        mapOverlays = mapView.getOverlays();
    } catch (Exception e) {
        Log.e("Error", "Exception", e);
    }
}

public OnTouchListener otl = new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {

        if (detector.onTouchEvent(event))
            return true;
        else
            return false;

    }
};

}

下面是朗pressMap

Here is the LongPressMap

public class LongPressMap extends AbstractMap {


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

}



@Override
public boolean onDown(MotionEvent event) {  

    return false;
}


public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) {


    return false;
}


@Override
public void onLongPress(MotionEvent e) {        

}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
        float distanceY) {
    //Log.d("Debug","On Scrtoll");
    // TODO Auto-generated method stub
    return false;
}

@Override
public void onShowPress(MotionEvent e) {


}

@Override
public boolean onSingleTapUp(MotionEvent e) {

    return false;
}

@Override
public boolean onDoubleTap(MotionEvent e) {

    return false;
}

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
    // TODO Auto-generated method stub
    return false;
}


@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

}

希望这有助于。