AndroidStudio:手勢識別
一內(nèi)容:設計一個手寫字體識別程序。
二實現(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手勢識別詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- 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 1.5 1.6 2.0 2.1 2.2 的區(qū)別詳解
本篇文章是對Android 1.5 1.6 2.0 2.1 2.2 版本之間的區(qū)別進行了詳細的分析介紹,需要的朋友參考下2013-06-06
解析android 流量監(jiān)測的實現(xiàn)原理
本篇文章是對android中流量監(jiān)測的實現(xiàn)原理進行了詳細的分析介紹,需要的朋友參考下2013-06-06
解決Android調(diào)用系統(tǒng)分享給微信,出現(xiàn)分享失敗,分享多文件必須為圖片格式的問題
這篇文章主要介紹了解決Android調(diào)用系統(tǒng)分享給微信,出現(xiàn)分享失敗,分享多文件必須為圖片格式的問題,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09
Android調(diào)試神器stetho使用詳解和改造
今天小編就為大家分享一篇關于Android調(diào)試神器stetho使用詳解和改造,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-02-02
Android BottomSheet效果的兩種實現(xiàn)方式
這篇文章主要介紹了Android BottomSheet效果的兩種實現(xiàn)方式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08
Studio 編譯報錯:compileSdkVersion ''android-24'' requires JDK 1.
今天小編就為大家分享一篇關于Studio編譯報錯:compileSdkVersion 'android-24' requires JDK 1.8 or later to compile.的解決辦法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-10-10

