使用Android的手势重叠视图 [英] Using a gesture overlay view in android

查看:121
本文介绍了使用Android的手势重叠视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想用一个手势重叠视图中的Andr​​oid做一个刷卡动作。因此,当用户挥笔离开它执行特定的code,当他们向右滑动则执行其他code。我想declairing这样的gestureoverlay:

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);

但后来我不知道从那里走,我不能找到任何的开发指南或联机帮助。对于一个按钮,我通常会使用onclicklistener我将如何做到这一点的姿态覆盖?任何人不会有code,我可以引用任何的例子吗?谢谢

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

推荐答案

首先让你自定义的手势建设者的姿态。手势制造商的应用程序自带的SDK。把从手势制造商的应用程序创建的文件到您要使用这些手势的应用程序的原始文件夹中。您也可以从文档帮助

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//
          }
        }
      }
    }
  }

这篇关于使用Android的手势重叠视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆