【问题标题】:Android Gestures are not being Recognized but onGesturePerformed() is being called. How do I get different gestures to be recognized?Android 手势未被识别,但 onGesturePerformed() 被调用。如何让不同的手势被识别?
【发布时间】:2012-06-29 19:42:28
【问题描述】:

我正在尝试让这段代码工作:
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());

... 之后,当我绘制手势时,会打印出一个空数组。

我做错了什么?我怎么知道正在绘制哪些手势?这种方法是如何工作的?

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

非常感谢。

【问题讨论】:

    标签: java android gesture gestures prediction


    【解决方案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();
            }
        }
    }
    

    【讨论】:

    • 如果您想查看所有预测等,只需查看所有 ArrayList。同样在 prediction.name 中,您拥有使用手势生成器定义的名称。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    相关资源
    最近更新 更多