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
0
投稿
猜你喜欢
- 一、关键字分类C语言一共多少个关键字呢?一般的书上,都是32个(包括本书),但是这个都是C90(C89)的标准。其实C99后又新增了5个关键
- 介绍建造者模式(Builder Pattern):将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。建造者模式是一种
- C#客户端程序,生成后是一个exe,如果带有大量的dll,那么dll和exe会混乱在一起,看起来非常混乱,我们可以建立一个文件夹,把dll放
- 如果使用了反向代理软件,将http://192.168.1.110:2046/ 的URL反向代理为http://www.xxx.com/ 的
- 引言Android studio 是2020 年的版本,有点老,昨天突发想法,升级到了 Android Studio Electric Ee
- 涉及access_token的获取请参考《C#微信公众平台开发之access_token的获取存储与更新》一、为了实现高级群发功能,需要解决
- mybatis的foreach标签经常用于遍历集合,构建in条件语句或者批量操作语句。下面是foreach标签的各个属性属性描述collec
- 我的安卓开发经历始于一个原生安卓项目开发。后来由于公司有个项目与几家医疗设备公司合作,需要我写安卓端的桥接代码给 react native
- yaml中的数组类型取值yaml中简单的风格,十分受大家的欢迎先说下简单的配置如何取值# application-dev.yml testV
- 对Jpa Entity关系映射中mappedBy的理解mappedBy 单向关系不需要设置该属性,双向关系必须设置,避免双方都建立外键字段数
- 网络应用模式主要有:主机/终端模式:集中计算,集中管理;客户机/服务器(Client/Server,简称C/S)模式:分布计算,分布管理;浏
- 一、EPL II 格式及打印测试注意N命令前的换行和最后P1后的换行。将此段代码复制到windows记事本里另存为Print.ext,文件名
- 技术场景在日常的开发、测试或运维的过程中,经常存在这样的场景,开发人员在代码中使用日志工具(log4j、slf4j)记录日志,比如请求ID、
- TCP/IP通信协议是一种可靠的网络协议,它在通信的两端各建立一个Socket,从而在通信的两端之间形成网络虚拟链路。一旦建立了虚拟的网络链
- Nashorn是什么Nashorn,发音“nass-horn”,是德国二战时一个坦克的命名,同时也是java8新一代的javascript引
- 一、简介1.什么是GUID?全局唯一标识符(GUID,Globally Unique Identifier),GUID也称作 UUID(Un
- 简介简单工厂模式 (Simple Factory) 又叫静态工厂方法(Static Factory Method)模式。简单工厂模式通常是定
- 1:HttpHelper.javapublic class HttpHelper { //1:标准的Ja
- CLR要求每一个类型都最终从object类型派生,如下: class Typer {} === class Typer :object {}
- 本文实例讲述了Android数据持久化之File机制。分享给大家供大家参考,具体如下:在使用Java SE平台开发C/S结构的软件中,Fil