Android手势识别 - 垂直线条

时间:2014-03-31 06:02:23

标签: android line gesture gesture-recognition

我正在创建一个Android应用程序。我在其中识别线(垂直和水平)。我使用了以下步骤。

1) Creating straight lines gesture file using "Gestures Builder" application. 
2) Added the "gestures" file in my application and used the "OnGesturePerformedListener" to recognize the line.

The problem is,
I can't recognize the vertical lines(Both Top to Bottom & Bottom to Top).

我可以识别垂直线以外的直线。谁能知道如何进行垂直线检测?

  

代码段:

public class GestureActivity extends Activity implements OnGesturePerformedListener {
    private GestureLibrary mLibrary;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
    View inflate = getLayoutInflater().inflate(R.layout.activity_gesture,
            null);
    gestureOverlayView.addView(inflate);
    gestureOverlayView.addOnGesturePerformedListener(this);
    mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
    if (!mLibrary.load()) {
        finish();
    }
    setContentView(gestureOverlayView);
}

@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
    ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
    if (predictions.size() > 0) {
        Prediction prediction = predictions.get(0);
        if (prediction.name.equals("Line") && prediction.score > 1.0) {
            Toast.makeText(this, "Line", Toast.LENGTH_LONG).show();
        }
    }

}

}

1 个答案:

答案 0 :(得分:1)

最后我找到了解决方案。答案如下:

gestureOverlayView.setGestureStrokeAngleThreshold( 90.0f);

参考:https://stackoverflow.com/a/22807326/1485254