在按照此处的手势教程进行操作时,我遇到了一个非常奇怪的问题:http: //developer.android.com/resources/articles/gestures.html。
在 Gesture Builder 中创建了 4 个独特的手势:+ - × /
加法和乘法是多笔画。减法和除法是单笔画法。
Activity 加载预构建的 GestureLibrary (R.raw.gestures),将 OnGesturePerformedListener 添加到 GestureOverlayView,并在检测到并执行手势时以 onGesturePerformed() 结束。
XML 中的活动布局
<android.gesture.GestureOverlayView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gestures"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gestureStrokeType="multiple"
android:eventsInterceptionEnabled="true"
android:orientation="vertical"
/>
位于 onCreate()
mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!mLibrary.load()) {
finish();
}
GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.addOnGesturePerformedListener(this);
位于 onGesturePerformed()
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();
}
}
主要问题是未正确识别预构建的手势。例如,如果水平手势后跟垂直(加法)手势,则永远不会执行 onGesturePerformed()。如果垂直手势后面跟着水平手势,则调用该方法。这也是 GesturesListDemo 的行为方式 ( GesturesDemos.zip @ code.google.com )。
此外,预测的手势最终成为不正确的手势。加法被识别为减法;乘除;减为加。这是完全不一致的。
最后,加法和减法手势通常共享相似的 Prediction.score,这很奇怪,因为它们在整个笔划上有所不同。
很抱歉这篇长篇文章 - 想要彻底。任何建议将不胜感激,谢谢大家。