问题描述
我在这里时跟随手势教程一个很奇怪的问题:。
I'm having a really weird problem while following the Gestures tutorial here: http://developer.android.com/resources/articles/gestures.html.
4独特的手势手势Builder创建:+ - ×/
4 unique gestures are created in Gesture Builder: + - × /
添加和乘法是多中风。减去和除法是单中风。
Add and multiply are multi-stroke. Subtract and divide are single stroke.
该活动加载pre-内置GestureLibrary(R.raw.gestures),增加了一个OnGesturePerformedListener到GestureOverlayView,并在检测和放手势onGesturePerformed()结束;执行
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.
在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();
}
}
的主要问题是在$ P $对内置手势没有被正确识别。例如,如果一个水平手势之后是垂直(加成)被从未执行onGesturePerformed()。该方法的是如果垂直手势后跟一个水平调用。这是GesturesListDemo的行为太(<一个href=\"http://$c$c.google.com/p/apps-for-android/downloads/detail?name=GesturesDemos.zip&can=2&q=\"相对=nofollow> GesturesDemos.zip @ code.google.com )。
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).
此外,predicted手势结束是不正确的姿态。添加被认为是减;如乘鸿沟;减去如添加。这是完全不一致的。
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.
最后,加减手势通常共享类似prediction.score的,因为它们通过整个行程不同,这是奇怪的。
Finally, add and subtract gestures typically share similar Prediction.score's, which is weird since they differ by an entire stroke.
很抱歉的长期职位 - 想成为彻底。任何意见将大大AP preciated,谢谢大家。
Sorry about the long post -- wanted to be thorough. Any advice would be greatly appreciated, thanks all.
推荐答案
我意识到这是一个很老的问题,但它尚未回答,这可能帮助别人。我只是碰到了类似的问题,我的解决方案是使用 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.
例如:
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) {
if (gesture.getStrokesCount() > 1) {
// This is either add or multiply
}
else {
// This is either subtract or divide
}
}
}
这篇关于Android的手势,单次行程和放大器;多冲程产生不一致的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!