AndroidStudio:手势识别
作者:Allison李沛 时间:2022-04-04 00:53:58
一内容:设计一个手写字体识别程序。
二实现
①建立一个存放手写字体的数据库
②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); // 注册手势识别的 *
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手势识别详解整合网站的支持!
来源:https://blog.csdn.net/weixin_40141473/article/details/89074833
标签:AndroidStudio,手势识别
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#自定义RSA加密解密及RSA签名和验证类实例
2023-08-08 17:48:11
java基础之注解示例详解
2022-05-08 23:47:20
![](https://img.aspxhome.com/file/2023/5/100675_0s.png)
关于Spring中的三级缓存解析
2022-08-20 15:31:06
![](https://img.aspxhome.com/file/2023/5/122965_0s.jpg)
使用JAVA实现http通信详解
2023-11-12 12:21:12
![](https://img.aspxhome.com/file/2023/4/61924_0s.png)
IDEA中sout快捷键无效问题的解决方法
2023-11-28 21:27:02
![](https://img.aspxhome.com/file/2023/7/60817_0s.png)
Entity Framework映射TPH、TPT、TPC与继承类
2022-10-18 04:52:52
Java HashMap三种循环遍历方式及其性能对比实例分析
2022-03-22 18:36:45
Java 中的 String对象为什么是不可变的
2023-08-04 03:24:32
![](https://img.aspxhome.com/file/2023/2/85892_0s.jpg)
Android自定义带动画的半圆环型进度效果
2022-02-08 09:31:15
c# 获取字符串的字节数的方法
2022-01-17 13:52:50
在SpringBoot中整合使用Netty框架的详细教程
2023-03-26 23:59:53
![](https://img.aspxhome.com/file/2023/8/72578_0s.png)
Java 从互联网上爬邮箱代码示例
2022-02-27 16:40:57
解决springboot 启动找不到主类的问题
2023-06-13 04:58:56
![](https://img.aspxhome.com/file/2023/6/68766_0s.jpg)
Spring Security前后分离校验token的实现方法
2023-06-26 17:00:30
![](https://img.aspxhome.com/file/2023/5/60665_0s.png)
基于Android中获取资源的id和url方法总结
2023-06-20 06:05:21
Android开发中如何模拟输入
2022-03-02 02:07:18
![](https://img.aspxhome.com/file/2023/9/113289_0s.png)
Android结束进程的方法详解
2023-06-09 20:27:30
Spring组件开发模式支持SPEL表达式
2023-09-05 11:53:31
Java接口中尽量避免使用数组
2022-07-06 23:24:14
![](https://img.aspxhome.com/file/2023/0/69930_0s.png)
Java设计模式中的桥接模式
2023-11-10 08:42:25
![](https://img.aspxhome.com/file/2023/8/113178_0s.png)