我有一個很奇怪的問題,而以下的手勢教程這裏:http://developer.android.com/resources/articles/gestures.html。
4個獨特手勢在手勢生成器中創建:+ - ×/
添加和乘法是多衝程。減法和除法是單行程。
活動加載預構建的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,這是奇怪的,因爲它們相差整個筆畫。
很抱歉,很長一段時間 - 想徹底。任何意見將不勝感激,謝謝大家。
這是一個很好的解決方案。我在答案中增加了進一步的實現。 – Robbe 2014-11-25 23:46:54