垂直的从上到下的手势检测器

时间:2014-04-02 07:26:27

标签: android

我使用了https://play.google.com/store/apps/details?id=com.davemac327.gesture.tool&hl=en

手势工具,并注意到对于垂直从上到下的线无法检测,因为我在我的代码中使用生成的手势文件如下,但无法检测到垂直的从上到下的手势检测

import java.util.ArrayList;

import android.app.Activity;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.Prediction;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.os.Bundle;
import android.widget.Toast;

public class GesturesActivity extends Activity implements OnGesturePerformedListener {
    private GestureLibrary mLibrary;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
        if (!mLibrary.load()) {
            finish();
        }

        GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
        gestures.addOnGesturePerformedListener(this);
    }

    public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
        ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
        String data="";
        for (int i = 0; i < predictions.size(); i++) {
            data=data+ "=="+predictions.get(i).name;

        }

        // 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,data+ "  "+ prediction.name, Toast.LENGTH_SHORT).show();
            }
        }
    }
}

请建议如何执行垂直从上到下的垂直手势检测

1 个答案:

答案 0 :(得分:2)

通过介绍

解决了上述代码的问题
   GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
        gestures.setGestureStrokeAngleThreshold( 90.0f);

因为角度threashold的默认值是40.0f,因为它会跳过简单的垂直手势,所以将其更改为90.0f,所以最后将Ge​​stureStrokeAngleThreshold设置为接近90.0f的值可以正常工作