AndroidStudio:手勢識別
更新時間:2019年04月19日 16:03:14 作者:Allison李沛
這篇文章主要介紹了AndroidStudio手勢識別,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
一內容:設計一個手寫字體識別程序。
二實現(xiàn)
①建立一個存放手寫字體的數(shù)據(jù)庫
②activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Gesture:" android:id="@+id/tv" android:textSize="24dp"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20dp" android:text="clear" android:id="@+id/bt"/> <android.gesture.GestureOverlayView android:layout_width="match_parent" android:layout_height="match_parent" android:gestureStrokeType="multiple" android:eventsInterceptionEnabled="false" android:orientation="vertical" android:id="@+id/gesture"></android.gesture.GestureOverlayView> </LinearLayout
3.MainActivity.java
package com.example.myapplication; import android.gesture.Gesture; import android.gesture.GestureLibraries; import android.gesture.GestureLibrary; import android.gesture.GestureOverlayView; import android.gesture.Prediction; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class MainActivity extends AppCompatActivity implements GestureOverlayView.OnGesturePerformedListener { GestureLibrary mLibrary; //定義手勢庫對象 GestureOverlayView gest; //定義手勢視圖對象做畫板之用 TextView txt; Button bt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gest = (GestureOverlayView)findViewById(R.id.gesture); gest.addOnGesturePerformedListener(this); // 注冊手勢識別的監(jiān)聽器 txt = (TextView)findViewById(R.id.tv); mLibrary = GestureLibraries.fromRawResource(this,R.raw.gestures); //加載手勢庫 bt = (Button)findViewById(R.id.bt); bt.setOnClickListener(new Click()); if (!mLibrary.load()) { finish(); } } /*根據(jù)畫的手勢識別是否匹配手勢庫里的手勢*/ @Override public void onGesturePerformed(GestureOverlayView gest, Gesture gesture) { ArrayList gestList = mLibrary.recognize(gesture); // 從手勢庫獲取手勢數(shù)據(jù) if (gestList.size() > 0) { Prediction pred = (Prediction)gestList.get(0); if (pred.score > 1.0) { // 檢索到匹配的手勢 Toast.makeText(this,pred.name,Toast.LENGTH_SHORT).show(); txt.append(pred.name); } } } private class Click implements View.OnClickListener { @Override public void onClick(View view) { txt.setText("Gesture:"); } } }
三效果
以上所述是小編給大家介紹的AndroidStudio手勢識別詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
您可能感興趣的文章:
- Android Studio使用小技巧:布局預覽時填充數(shù)據(jù)
- Android Studio使用小技巧:提取方法代碼片段
- Android Studio使用教程(二):基本設置與運行
- Android Studio使用教程(一):下載與安裝及創(chuàng)建HelloWorld項目
- Android Studio的中文亂碼問題解決方法
- Mac OS下為Android Studio編譯FFmpeg解碼庫的詳細教程
- 圖解Windows環(huán)境下Android Studio安裝和使用教程
- Android Studio注釋模板介紹
- Android Studio使用小技巧:自定義Logcat
- AndroidStudio 使用過程中出現(xiàn)的異常(Gradle sync failed)處理辦法
相關文章
Android App使用RecyclerView實現(xiàn)上拉和下拉刷新的方法
RecyclerView一經推出便被認為是替代ListView的存在,那么ListView的上拉和下拉刷新我們同樣可以使用RecyclerView來做到,這里我們就來看一下Android App使用RecyclerView實現(xiàn)上拉和下拉刷新的方法,首先先來點RecyclerView的小介紹:2016-06-06Android ViewPager與radiogroup實現(xiàn)關聯(lián)示例
本篇文章主要介紹了Android ViewPager與radiogroup實現(xiàn)關聯(lián)示例,具有一定的參考價值,有興趣的可以了解一下。2017-03-03基于Android studio3.6的JNI教程之helloworld思路詳解
這篇文章主要介紹了基于Android studio3.6的JNI教程之helloworld,本文通過圖文實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03Android Studio屏幕方向以及UI界面狀態(tài)的保存代碼詳解
在本篇文章里小編給各位整理的是關于Android Studio屏幕方向以及UI界面狀態(tài)的保存代碼以及相關知識點,需要的跟著學習下。2019-10-10