代码之家  ›  专栏  ›  技术社区  ›  SKK

Android手势识别-垂直线

  •  0
  • SKK  · 技术社区  · 10 年前

    我正在创建一个android应用程序。其中我正在识别直线(垂直和水平)。我使用了以下步骤。

    1) Creating straight lines gesture file using "Gestures Builder" application. 
    2) Added the "gestures" file in my application and used the "OnGesturePerformedListener" to recognize the line.
    
    The problem is,
    I can't recognize the vertical lines(Both Top to Bottom & Bottom to Top).
    

    我能认出直线而不是竖线。有人知道如何检测垂直线吗?

    代码段:

    public class GestureActivity extends Activity implements OnGesturePerformedListener {
        private GestureLibrary mLibrary;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
        View inflate = getLayoutInflater().inflate(R.layout.activity_gesture,
                null);
        gestureOverlayView.addView(inflate);
        gestureOverlayView.addOnGesturePerformedListener(this);
        mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
        if (!mLibrary.load()) {
            finish();
        }
        setContentView(gestureOverlayView);
    }
    
    @Override
    public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
        ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
        if (predictions.size() > 0) {
            Prediction prediction = predictions.get(0);
            if (prediction.name.equals("Line") && prediction.score > 1.0) {
                Toast.makeText(this, "Line", Toast.LENGTH_LONG).show();
            }
        }
    
    }
    

    }

    1 回复  |  直到 10 年前
        1
  •  1
  •   Community raghavsood33    7 年前

    最后我找到了解决办法。答案如下。

    gestureOverlayView.setGestureStrokeAngleThreshold( 90.0f);
    

    裁判: https://stackoverflow.com/a/22807326/1485254