zoukankan      html  css  js  c++  java
  • android之手势添加&识别

       布局XML:

         <android.gesture.GestureOverlayView

       android:id="@+id/gesture1"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:gestureStrokeType="multiple">
         </android.gesture.GestureOverlayView>
    ***android.gesture.GestureOverlayView是手势输入视图,注意的就是这里的标签不是GestureOverlayView

    以下先来讲一讲添加手势的方法:

        1.收先取得手势库

        GestureLibrary gestureLibrary = GestureLibraries.fromFile("/sdcard/mygestures");

        2.判断手势的加载是否成功

        if(gestureLibrary.load()){
        Toast.makeText(registerDialog.this, "文件装载成功,输入你要修改的手势", Toast.LENGTH_LONG).show();
        }else{
          Toast.makeText(registerDialog.this, "文件装载不成功", Toast.LENGTH_SHORT).show();
        }

        3.对手势绘制完成后进行事件监听addOnGesturePerformedListener

        4.添加手势以及保存手势

         gestureLibrary.addGesture("默认手势", gesture);

           gestureLibrary.save();

    再来说一下手势的识别:

        1.首先取得手势库

        GestureLibrary gestureLibrary = GestureLibraries.fromFile("/sdcard/mygestures");

        2.判断手势库是否加载成功

        if(library.load())

        3.对手势绘制完成后进行事件监听addOnGesturePerformedListener

        4.调用GestureLibrary方法的recognize(Gesture gesture)返回ArrayList<Prediction>对象

        5.循环遍历ArrayList<Prediction>对象,使用Prediction的score来匹配手势的相似度,ArrayList中保存所有与匹配手势匹配的候选手势

  • 相关阅读:
    linux安装kibana
    linux安装6.5.3版本elastic search
    linux非root用户安装nginx
    linux非root用户安装ncurses-devel依赖
    linux无网络情况下安装rpm包
    linux非root用户安装rabbitmq
    linux非root用户安装4.0.14版本redis
    (初)Knockout 监控属性(Observables)
    ECMAScript6
    SonarLint 代码质量管理
  • 原文地址:https://www.cnblogs.com/lee0oo0/p/2393509.html
Copyright © 2011-2022 走看看