Android: Gestures don't execute well

I want to use Gesturein my application. So I checked this documentation and already created a gesture. Then copy this gesture to my folder raw, which is located in res/.

Everything is fine from here, then I impelement OnGesturePerformedListeneras shown below:

if(!mLibrary.load()) {
    Log.d("Tag", "Couldn't load");
} else {
    Log.d("Tag", "Loaded");
    GestureOverlayView gesture = (GestureOverlayView) findViewById(R.id.gestures);
    gesture.addOnGesturePerformedListener(this);
}

And finally, here is my listener:

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
    ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
    Log.d("Tag", "Performed");
    // 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();
        }
    }
}

The problem is that when you try to draw a gesture, nothing changes. onGesturePerformedDoesn't even work. What is the problem?

I'm not sure, but maybe the layout can call, here it is:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/splash_bg"
    android:screenOrientation="portrait" >

    <android.gesture.GestureOverlayView
        android:id="@+id/gestures"
        android:layout_width="fill_parent" 
        android:layout_height="0dip"
        android:layout_weight="1.0" />    

</RelativeLayout>

Any help would be great.

+5
source share
1 answer

You must fill the entire gesture area with GestureOverlayView. Change

android:layout_height="0dip"

to

android:layout_height="fill_parent"

Gotta do the trick.

+3
source

All Articles