1

Gestures Builder アプリを実行し、左右にスライドするためのジェスチャ ファイルを作成し、次のコードを記述しました。

public class MainActivity extends Activity implements OnGesturePerformedListener {

    private GestureLibrary mGestureLibrary;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
        View inflate = getLayoutInflater().inflate(R.layout.main, null);
        gestureOverlayView.addView(inflate);
        gestureOverlayView.addOnGesturePerformedListener(this);
        mGestureLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
        if (mGestureLibrary == null) {
            finish();
        }

        setContentView(gestureOverlayView);
    }

    @Override
    public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
        ArrayList<Prediction> predictions = mGestureLibrary.recognize(gesture);

        for (Prediction prediction : predictions) {
            if (prediction.score > 1.0) {
                Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT).show();
            }
        }
    }
}

ジェスチャは /raw/ にありますが、アプリをテストしようとしても何も言いません (ジェスチャが正常に読み込まれ、イベント onGesturePerformed が呼び出されますが、ジェスチャは認識されません)。ジェスチャは Gestures Builder で完全に機能しますが、どこが間違っているのでしょうか?

4

2 に答える 2

0

アクションのいずれかの名前と一致する予測の名前を確認する必要があります。等しいかどうかをテストしてから、ロジックを実行します。

String action = predictions.get(0).name;
 if("right".equals(action){
}
于 2012-02-06T17:42:01.133 に答える
0

You may need to call load() on mGestureLibrary before using it. Not that it's documented at all, but that's what Lars does in this example and it works for me: http://www.vogella.com/articles/AndroidGestures/article.html

In the IDE you should be able to see entries in the GestureStore HashMap (mNamedGestures).

于 2012-07-12T15:57:30.447 に答える