2013-08-22 18 views
0

我一直在使用droidQuery庫,這真的很棒,易於使用。目前爲止,我主要用它來進行自定義手勢檢測。我有一個swipeInterceptorView用滑動偵聽器來檢測滑動,但我也需要檢測捏和縮放我的應用程序。謝謝!Android的Droid查詢如何識別捏和縮放

回答

2

droidQuery庫目前不支持縮放捏,但是你可以使用droidQuery的重擊能力與的AndroidScaleGestureDetector讓你正在尋找的手勢檢測。

下面的例子,應該可以幫助你:

public class MyActivity extends Activity { 

    private float scaleFactor = 1.0f; 
    private ScaleGestureDetector scaleGestureDetector; 
    private SwipeInterceptorView view; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     //set main view to the main layout 
     setContentView(R.layout.main); 
     //get a reference to the content view 
     view = (SwipeInterceptorView) findViewById(R.id.swipe_view); 
     //get the scale gesture detector 
     scaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener()); 
     //add Swiper 
     view.setSwipeListener(new SwipeListener() { 
      public void onUpSwipe(View v) { 
       //TODO handle up swipe 
      } 
      public void onRightSwipe(View v) { 
       //TODO handle right swipe 
      } 
      public void onLeftSwipe(View v) { 
       //TODO handle left swipe 
      } 
      public void onDownSwipe(View v) { 
       //TODO handle down swipe 
      } 
     }); 
     view.setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       if (scaleGestureDetector.onTouchEvent(event))//this will cause a pinch zoom if two fingers are down 
        return true; 
       //if no pinch zoom was handled, the swiping gesture will take over. 
       return super.onTouch(v, event); 
      } 
     }); 
    } 

    //this inner class copied from http://www.vogella.com/articles/AndroidTouch/article.html#scaleGestureDetector 
    private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { 
     @Override 
     public boolean onScale(ScaleGestureDetector detector) { 
      scaleFactor *= detector.getScaleFactor(); 

      // Don't let the object get too small or too large. 
      scaleFactor = Math.max(0.1f, Math.min(scaleFactor, 5.0f)); 

      view.invalidate(); 
      return true; 
     } 
    } 
} 
+0

的夾持和縮放被認爲是刷卡 – superuser

+0

@superuser是這樣,而不是放大,或用它? – Phil

+0

它代替縮放。 – superuser