AndroidStudio:手勢(shì)識(shí)別
一內(nèi)容:設(shè)計(jì)一個(gè)手寫(xiě)字體識(shí)別程序。
二實(shí)現(xiàn)
①建立一個(gè)存放手寫(xiě)字體的數(shù)據(jù)庫(kù)
②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; //定義手勢(shì)庫(kù)對(duì)象
GestureOverlayView gest; //定義手勢(shì)視圖對(duì)象做畫(huà)板之用
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); // 注冊(cè)手勢(shì)識(shí)別的監(jiān)聽(tīng)器
txt = (TextView)findViewById(R.id.tv);
mLibrary = GestureLibraries.fromRawResource(this,R.raw.gestures); //加載手勢(shì)庫(kù)
bt = (Button)findViewById(R.id.bt);
bt.setOnClickListener(new Click());
if (!mLibrary.load()) {
finish();
}
}
/*根據(jù)畫(huà)的手勢(shì)識(shí)別是否匹配手勢(shì)庫(kù)里的手勢(shì)*/
@Override
public void onGesturePerformed(GestureOverlayView gest, Gesture gesture) {
ArrayList gestList = mLibrary.recognize(gesture); // 從手勢(shì)庫(kù)獲取手勢(shì)數(shù)據(jù)
if (gestList.size() > 0) {
Prediction pred = (Prediction)gestList.get(0);
if (pred.score > 1.0) { // 檢索到匹配的手勢(shì)
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手勢(shì)識(shí)別詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- Android Studio使用小技巧:布局預(yù)覽時(shí)填充數(shù)據(jù)
- Android Studio使用小技巧:提取方法代碼片段
- Android Studio使用教程(二):基本設(shè)置與運(yùn)行
- Android Studio使用教程(一):下載與安裝及創(chuàng)建HelloWorld項(xiàng)目
- Android Studio的中文亂碼問(wèn)題解決方法
- Mac OS下為Android Studio編譯FFmpeg解碼庫(kù)的詳細(xì)教程
- 圖解Windows環(huán)境下Android Studio安裝和使用教程
- Android Studio注釋模板介紹
- Android Studio使用小技巧:自定義Logcat
- AndroidStudio 使用過(guò)程中出現(xiàn)的異常(Gradle sync failed)處理辦法
相關(guān)文章
Android 5秒學(xué)會(huì)使用手勢(shì)解鎖功能
本文講述的是一個(gè)手勢(shì)解鎖的庫(kù),可以定制顯示隱藏宮格點(diǎn)、路徑、并且?guī)в行【艑m格顯示圖,和震動(dòng)!讓你學(xué)會(huì)使用這個(gè)簡(jiǎn)單,高效的庫(kù),好了,具體內(nèi)容詳情大家通過(guò)本文學(xué)習(xí)吧2017-12-12
Android App使用RecyclerView實(shí)現(xiàn)上拉和下拉刷新的方法
RecyclerView一經(jīng)推出便被認(rèn)為是替代ListView的存在,那么ListView的上拉和下拉刷新我們同樣可以使用RecyclerView來(lái)做到,這里我們就來(lái)看一下Android App使用RecyclerView實(shí)現(xiàn)上拉和下拉刷新的方法,首先先來(lái)點(diǎn)RecyclerView的小介紹:2016-06-06
Android ViewPager與radiogroup實(shí)現(xiàn)關(guān)聯(lián)示例
本篇文章主要介紹了Android ViewPager與radiogroup實(shí)現(xiàn)關(guān)聯(lián)示例,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-03-03
基于Android studio3.6的JNI教程之helloworld思路詳解
這篇文章主要介紹了基于Android studio3.6的JNI教程之helloworld,本文通過(guò)圖文實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
Android 自定義Switch開(kāi)關(guān)按鈕的樣式實(shí)例詳解
本文主要講的是在Android原生Switch控件的基礎(chǔ)上進(jìn)行樣式自定義,內(nèi)容很簡(jiǎn)單,但是在實(shí)現(xiàn)的過(guò)程中還是遇到了一些問(wèn)題,在此記錄下來(lái),需要的朋友參考下吧2017-12-12
Android Studio屏幕方向以及UI界面狀態(tài)的保存代碼詳解
在本篇文章里小編給各位整理的是關(guān)于Android Studio屏幕方向以及UI界面狀態(tài)的保存代碼以及相關(guān)知識(shí)點(diǎn),需要的跟著學(xué)習(xí)下。2019-10-10
IOS開(kāi)發(fā)向右滑動(dòng)返回前一個(gè)頁(yè)面功能(demo)
本文給大家介紹使用android實(shí)現(xiàn)向右滑動(dòng)返回一個(gè)頁(yè)面的功能,大家都知道在ios7中,蘋(píng)果的原生態(tài)應(yīng)用幾乎都能夠通過(guò)向右滑動(dòng)來(lái)返回到前一個(gè)頁(yè)面,這樣可以避免用戶在單手操作時(shí)用大拇指去點(diǎn)擊那個(gè)遙遠(yuǎn)的返回鍵,下面小編就給帶來(lái)了實(shí)現(xiàn)代碼,有需要的朋友可以參考下2016-06-06
Android app啟動(dòng)時(shí)黑屏或者白屏的原因及解決辦法
這篇文章主要介紹了Android app啟動(dòng)時(shí)黑屏或者白屏的原因及解決辦法的相關(guān)資料,需要的朋友可以參考下2016-09-09

