Android 手势、单笔划和多次冲程产生不一致的结果
我在遵循此处的手势教程时遇到了一个非常奇怪的问题:http://developer.android.com/resources/articles/gestures.html。
Gesture Builder 中创建了 4 个独特的手势:+ - × /
加法和乘法是多笔画。减法和除法都是单笔画。
Activity 加载预构建的 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,这很奇怪,因为它们在整个笔画上有所不同。
抱歉,这篇文章很长——我想写得彻底。任何建议将不胜感激,谢谢大家。
I'm having a really weird problem while following the Gestures tutorial here: http://developer.android.com/resources/articles/gestures.html.
4 unique gestures are created in Gesture Builder: + - × /
Add and multiply are multi-stroke. Subtract and divide are single stroke.
The Activity loads the pre-built GestureLibrary (R.raw.gestures), adds an OnGesturePerformedListener to the GestureOverlayView, and ends with onGesturePerformed() when a gesture is detected & performed.
Activity layout in 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"
/>
Located in onCreate()
mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!mLibrary.load()) {
finish();
}
GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.addOnGesturePerformedListener(this);
Located in 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();
}
}
The main problem is the pre-built gestures are not being recognized correctly. For example, onGesturePerformed() is never performed if a horizontal gesture is followed by a vertical (addition). The method is called if a vertical gesture is followed by a horizontal. This is how GesturesListDemo behaves too (GesturesDemos.zip @ code.google.com).
Furthermore, the predicted gesture ends up being the incorrect gesture. Add is recognized as subtract; multiply as divide; Subtract as add. It's completely inconsistent.
Finally, add and subtract gestures typically share similar Prediction.score's, which is weird since they differ by an entire stroke.
Sorry about the long post -- wanted to be thorough. Any advice would be greatly appreciated, thanks all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我意识到这是一个非常古老的问题,但尚未得到解答,这可能会对某人有所帮助。我刚刚遇到了类似的问题,我的解决方案是使用 gesture.getStrokesCount() 来区分单笔画和多笔画手势。
例子:
I realize this is a really old question, but it hasn't been answered yet and this might help someone. I just came across a similar problem and my solution was to use
gesture.getStrokesCount()
to differentiate between single- and multi-stroke gestures.Example:
基于 Drew Lederman 的回答,您可以使用 onGesturePerformed 的实现来始终获得最佳结果:
Building on Drew Lederman his answer, you can use this implementation of onGesturePerformed to always get the best result:
是的,至少从 Android 2.3.3 开始支持。但它非常不精确。 查看第二个示例。
Yes, are supported, at least from Android 2.3.3. But it is heavily imprecise. Check the second example.