2012-01-06 21 views
2

我已經閱讀了關於android的手勢,甚至在這個網站上發現了類似的問題,但沒有給出解決方案。所以我再問一次。onGesturePerformed不識別手勢,總是返回null

我想使用GestrueOverlay翻閱視圖切換器。我運行了手勢構建器,將手勢文件移動到了我的res/raw中,並在我的XML中添加了疊加層並實現了偵聽器。我基本上從谷歌指令複製代碼。

我可以看到聽衆跟蹤手勢,從淡黃色變爲暗黃色,但它不會識別手勢。我寫了一篇敬酒文件來找出預測的大小,並且總是讀取ZERO。

請幫助,並感謝您的時間。

這裏是的onCreate代碼

 mLibrary = GestureLibraries.fromRawResource(LayoutView.getContext(), R.raw.gestures); 
     gestures = (GestureOverlayView) LayoutView.findViewById(R.id.gestures);  
     gestures.addOnGesturePerformedListener(this); 

這裏是監聽器代碼

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { 
    ArrayList<Prediction> predictions = mLibrary.recognize(gesture); 
    Toast.makeText(LayoutView.getContext(), String.valueOf(predictions.size()), Toast.LENGTH_SHORT).show(); 

    // We want at least one prediction 
    if (predictions.size() > 0) { 
     Prediction prediction = (Prediction) predictions.get(0); 
     // We want at least some confidence in the result 
     if (prediction.score > 1.0) { 
      // Show the spell 
      Toast.makeText(overlay.getContext(), prediction.name, Toast.LENGTH_SHORT).show(); 
     } 
    } 
} 

回答

0

對於那些誰具有相同的問題,因爲我有,我想我會後我的解決方案。在定義它之後,您必須加載手勢庫。我認爲

mLibrary = GestureLibraries.fromRawResource(LayoutView.getContext(), R.raw.gestures); 

從資源加載手勢,並且如果加載成功,mLibrary.load只是一個布爾值。我的錯誤是我沒有使用這種方法。實際上,您還必須使用庫上的加載方法加載手勢。

新手錯誤,你生活和學習。

+0

謝謝。我有同樣的問題。 – 2012-08-07 07:09:33