日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

java 手势识别,AndroidStudio:手势识别

發布時間:2024/9/3 Android 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 手势识别,AndroidStudio:手势识别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一內容:設計一個手寫字體識別程序。

二實現

①建立一個存放手寫字體的數據庫

②activity_main.xml

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">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Gesture:"

android:id="@+id/tv"

android:textSize="24dp"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textSize="20dp"

android:text="clear"

android:id="@+id/bt"/>

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gestureStrokeType="multiple"

android:eventsInterceptionEnabled="false"

android:orientation="vertical"

android:id="@+id/gesture">

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); // 注冊手勢識別的監聽器

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();

}

}

/*根據畫的手勢識別是否匹配手勢庫里的手勢*/

@Override

public void onGesturePerformed(GestureOverlayView gest, Gesture gesture) {

ArrayList gestList = mLibrary.recognize(gesture); // 從手勢庫獲取手勢數據

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手勢識別詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!

總結

以上是生活随笔為你收集整理的java 手势识别,AndroidStudio:手势识别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。