Double tap: zoom on Android MapView?

前端 未结 6 1189
慢半拍i
慢半拍i 2020-11-29 13:15

After a little bit of work my route application works fine. The only thing I just want to add is a double tap zoom in function, but I don\'t know how.

Could you give

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 13:25

    Use the following code when you want to zoom in and zoom out

    1. zoom in double click on top 50% of mapview
    2. Zoom out double click on bottom 50% of mapview

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
          long thisTime = System.currentTimeMillis();
    
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) activity.getSystemService(activity.getApplicationContext().WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(metrics);
    int height = metrics.heightPixels; 
    
    if (thisTime - lastTouchTime < ViewConfiguration.getDoubleTapTimeout()) {
            // Double tap
             if((height/2)>ev.getY()){
    // Zoom IN
                this.getController().zoomInFixing((int) ev.getX(), (int) ev.getY());
            }else{
                this.getController().zoomOutFixing((int) ev.getX(), (int) ev.getY());
    //Zoom Out
            }
            lastTouchTime = -1;
          } else {
            // Too slow 
            lastTouchTime = thisTime;
          }
        }
        return super.onInterceptTouchEvent(ev);
      }
    

提交回复
热议问题