1

+ - × /

ここでジェスチャのチュートリアルに従っているときに、私は本当に奇妙な問題を抱えています: http://developer.android.com/resources/articles/gestures.html .

Gesture Builder で作成される 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 を共有しますが、ストローク全体が異なるため、これは奇妙です。

長い投稿で申し訳ありません-徹底したかった. どんなアドバイスでも大歓迎です、ありがとう。

4

3 に答える 3

1

Building on Drew Lederman his answer, you can use this implementation of onGesturePerformed to always get the best result:

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {

        ArrayList<Prediction> predictions = store.recognize(gesture);
        double highScore = 0;
        String gestureName = "";

        for (Prediction prediction : predictions) {

            if (prediction.score > SCORE && prediction.score > highScore && 
                    store.getGestures(prediction.name).get(0).getStrokesCount() == gesture.getStrokesCount()) {

                highScore = prediction.score;
                gestureName = prediction.name;

            }
        }
        // Do something with gestureName
    }
于 2014-11-25T23:50:16.740 に答える
0

はい、少なくともAndroid2.3.3からはサポートされています。しかし、それは非常に不正確です。2番目の例を確認してください

于 2012-04-20T17:42:53.243 に答える