AndroidStudio:手势识别
作者:Allison李沛 发布时间:2022-04-04 00:53:58
标签:AndroidStudio,手势识别
一内容:设计一个手写字体识别程序。
二实现
①建立一个存放手写字体的数据库
②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


猜你喜欢
- 1.所有流程的起点是从拨号后按下拨号键开始,此步的代码在/android sourcecode/packages/Contacts/src/
- springboot logback动态获取application的配置项在多环境的情况下,logback的日志路径需要进行针对性配置,也就
- 向shell提供命令非常简单,需要学习的注解很少。该命令的实现风格与使用依赖注入的应用程序的开发类相同,您可以利用Spring容器的所有特性
- 使用ModelAndView向request域对象共享数据index.html<a th:href="@{/testMode
- 日期格式处理在控制器中使用对象接收数据前端:<form action="test/add" method=&quo
- 消息发送过程消息的发送可能会经过 * 、序列化、分区器等过程。消息发送的主要涉及两个线程,分别为main线程和sender线程。如图所示,主
- 本文实例讲述了Java对象数组定义与用法。分享给大家供大家参考,具体如下:所谓的对象数组,就是指包含了一组相关的对象,但是在对象数组的使用中
- 这里记录下C#中using关键字的使用方法。Using的使用大致分别以下三种:1 :using 指令(命名空间)using System;u
- 前言大富翁,又名地产大亨。是一种多人策略图版游戏。参与者分得游戏金钱,凭运气(掷骰子)及交易策略,买地、建楼以赚取租金。英文原名monopo
- 实践仿照@EnableEurekaServer实现自动装配如果你使用过Eureka作为微服务的注册中心,那么对@EnableWebConfi
- 一. String对象的比较1. ==比较是否引用同一个对象注意:对于内置类型,==比较的是变量中的值;对于引用类型 , == 比较的是引用
- 这几年一直在做手机上和电视盒的App,几乎没有考虑过横竖屏切换的问题。电视盒好说,横屏不变,你要是给它设计个竖屏人家也没机会使;而手机上的应
- 1,在项目上鼠标右键 --> Open Module Settings2, Artifacts --> + --> JAR
- SpringBoot2.3.1版本源码一、SpringBoot启动的时候加载主配置类,通过@EnableAutoConfiguration注解
- 集合的创建和遍历方式集合只要包含List和Set在宽泛一些就包括Map这种键值对类型的数据结构List,Set和Map在java当中都是接口
- SpringBoot 如何进行参数校验在日常的接口开发中,为了防止非法参数对业务造成影响,经常需要对接口的参数做校验,例如登录的时候需要校验
- 本文实例为大家分享了java实现打字游戏的具体代码,供大家参考,具体内容如下import java.util.Random;import j
- 目录服务注册服务发现服务注册引入相关依赖:<?xml version="1.0" encoding="U
- 本文为大家分享了实现断点续传下载的具体代码,供大家参考,具体内容如下1、基于Ok+Rxjava实现断点续传下载2、基于Ok+Rxjava+R
- 常见Bean后处理器的作用:public static void main(String[] args) { &