AndroidStudio:手势识别

发布时间:2019-08-08 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了AndroidStudio:手势识别脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

一内容:设计一个手写字体识别程序。

二实现

①建立一个存放手写字体的数据库

②activITy_main.XMl

 <&#63;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); // 注册手势识别的监听器     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:手势识别

android教程
脚本网站
android studio

脚本宝典总结

以上是脚本宝典为你收集整理的AndroidStudio:手势识别全部内容,希望文章能够帮你解决AndroidStudio:手势识别所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。