2012-11-10 36 views
0

我在我的应用程序中获得了MapView。 我有很多OverlayItems在里面有一点可绘制的标记。缩放和MapView中的onTap正在混合,如何解决它?

如果我触摸overlayitem,onTap()方法运行,并且我得到一个小对话框。 这是很好的作品,但有时当我尝试使用多点触控进行缩放时,手指位于overlayitem之上时,对话框在我完成缩放后出现。它有点儿怪异,因为它不符合人体工程学,因为在缩放后必须关闭即将出现的对话框。

我应该如何阻止我的应用程序从这个事件? 我不想让onTap()在im放大时运行。

我onTouch活动,并与2个布尔值,但不工作尝试过:

@Override 
    public boolean onTouchEvent(MotionEvent event, MapView mapView) { 

     int action = event.getAction() & MotionEvent.ACTION_MASK; 

     switch (action) { 
       case MotionEvent.ACTION_DOWN: { 
        actionIsDown= true; 
        break; 
       } 

       case MotionEvent.ACTION_POINTER_DOWN: { 

        pointerIsDown=true; 
         break; 
       } 
       case MotionEvent.ACTION_POINTER_UP: { 

        pointerIsDown= false; 
         break; 
       } 
       case MotionEvent.ACTION_UP: { 

        actionIsDown= false; 
         break; 
       } 
     } 


     return super.onTouchEvent(event, mapView); 
    } 

而且和Ontap:

@Override 
    protected boolean onTap(int index) 
    { 



      if(pointerIsDown==false && actionIsDown==false){ //...dialog here 

任何想法?

回答

2

您的代码不工作,因为onTap()被触发时,MotionEvent.ACTION_POINTER_UPMotionEvent.ACTION_UP发生,而不是MotionEvent.ACTION_POINTER_DOWNMotionEvent.ACTION_DOWN

要正确测试它,您需要在UP动作中检查动作是否用于缩放地图,然后将其保存到布尔值。

示例代码:

Geopoint center = new Geopoint(0,0); 
Boolean ignoreTap = false; 

@Override 
public boolean onTouchEvent(MotionEvent event, MapView mapView) { 

    int action = event.getAction() & MotionEvent.ACTION_MASK; 

    switch (action) { 
      case MotionEvent.ACTION_POINTER_DOWN: { 
      case MotionEvent.ACTION_DOWN: { 
       center = mapView.getMapCenter(); 
       ignoreTap = false; 
       break; 
      } 

      case MotionEvent.ACTION_UP: { 
      case MotionEvent.ACTION_POINTER_UP: { 
        if(center != mapView.getMapCenter()) 
        ignoreTap = true; 
        break; 
      } 
    } 
    return super.onTouchEvent(event, mapView); 
} 

onTap():使用地图中心

@Override 
protected boolean onTap(int index) 
{ 
     if(!ignoreTap){ //...dialog here 

Note: I'm测试变焦,如多点触摸变焦工作角落找寻位于手指之间的映射点中心,在缩放时导致中心更改。你也可以使用地图的经度跨度。

+0

我做了什么样的初学者错误。万分感谢的人! –

+0

不客气:-) – Luis