Android手势未被识别,但正在调用onGesturePerformed()。如何识别不同的手势?

时间:2012-06-29 19:42:28

标签: java android gesture gestures prediction

我正在尝试使用此代码:
http://scanplaygames.com/?p=168 (也在这里的stackoverflow上): Adding GestureOverlayView to my SurfaceView class, how to add to view hierarchy?

我运行了代码并添加了打印出预测的标签。

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) 
{
    // TODO Auto-generated method stub
    ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
    Log.d(TAG, predictions.toString());

... 在这样做之后,当我画出手势时,会打印出一个空数组。

我做错了什么?我如何知道正在绘制哪些手势?这种方法有什么用?

另外,我的手势文件有问题吗?我只是不确定。

非常感谢。

1 个答案:

答案 0 :(得分:1)

我认为错误可能在于你对预测的使用。它是一个ArrayList,所以你必须得到第一个(0)。

尝试这样的事情:

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

    // 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) {
            // Show the spell
            Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT).show();
        }
    }
}