Using a gesture overlay view in android

So I'm trying to use a gesture overlay view in android to make a "swipe" action. So that when the user "swipes" left it executes certain code and when they swipe right it executes other code. I tried declairing the gestureoverlay like this:

GestureOverlayView gest = (GestureOverlayView) findViewById(R.id.hatgest);

But then i don't know where to go from there and i cant find anything helpful in the dev guide or online. For a button i would normally use an "onclicklistener" how would i do this with the gesture overlay? Does anyone have any examples of code that i can reference? Thanks


Firstly make you custom gestures from gesture builder. Gesture builder app comes in the sdk. Put the file created from gesture builder app into raw folder of the application you are about to use these gestures. You can also get help from documentation

  public class YourClass extends Activity implements OnGesturePerformedListener {

    private GestureLibrary mLibrary;
    mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
    if (!mLibrary.load()) {
      finish();
    }

    GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
    gestures.addOnGesturePerformedListener(this);

    public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
      ArrayList < Prediction > predictions = mLibrary.recognize(gesture);
      Log.v("performed", "performed");

      // We want at least one prediction
      if (predictions.size() > 0) {
        Prediction prediction = predictions.get(0);

        // We want at least some confidence in the result
        if (prediction.score > 1.0) {
          if (prediction.name.equalsIgnorecase("right")) {
            //do you thing here//
          }
        }
      }
    }
  }

Apparently GestureOverlayViews can have multiple onGestureListeners.

Check out the method addOnGestureListener() and addOnGesturePerformedListener().

链接地址: http://www.djcxy.com/p/91318.html

上一篇: Android ViewFlipper +手势检测器

下一篇: 在android中使用手势叠加视图