我想Gesture
在我的应用程序中使用。所以我已经查看了这个文档并已经创建了一个手势。然后将该手势复制到我raw
位于的文件夹中res/
。
从这里开始一切正常,然后我执行OnGesturePerformedListener
如下所示:
if(!mLibrary.load()) {
Log.d("Tag", "Couldn't load");
} else {
Log.d("Tag", "Loaded");
GestureOverlayView gesture = (GestureOverlayView) findViewById(R.id.gestures);
gesture.addOnGesturePerformedListener(this);
}
最后是我的听众:
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();
}
}
}
问题是当我尝试绘制手势时没有任何变化。甚至onGesturePerformed
不工作。什么问题?
我不确定,但也许布局可能会导致,这里是:
<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>
任何帮助都会很棒。