我运行 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 Buileder 中完美运行,那么我的错误在哪里?