android之手勢添加&識別

來源:互聯網
上載者:User

   布局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中儲存所有與匹配手勢匹配的候選手勢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.