温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android手势的识别

发布时间:2020-03-17 18:16:37 来源:网络 阅读:435 作者:YuLi1207 栏目:移动开发

 手势保存了就可以开始识别了。

 

// 从资源文件中将手势库加载进来
		if (mGre == null) {
			Log.e("", "手势");
			mGre = GestureLibraries.fromRawResource(this, R.raw.yl_yl);
			// 无此句出错
			mGre.load();
		}
		// 从xml中取出GestureOverlayView控件
		mGov = (GestureOverlayView) findViewById(R.id.gesture);
		mGov.setGestureColor(Color.BLACK);// 手势颜色
		mGov.setGestureStrokeWidth(15);// 手势宽度
		// 为GestureOverlayView控件添加监听
		mGov.addOnGesturePerformedListener(this);

开始识别:

// 识别手势,返回一个类型为Prediction的列表
		ArrayList<Prediction> gestureList = mGre.recognize(gesture);
		if (gestureList.size() > 0) {
			Prediction pd = gestureList.get(0);
			// 如果匹配度大于1,表示可以识别,否则提示无法识别
			if (pd.score > 3) {
				// 判断名字是否与手势库的名字相同
				if (pd.name.equals("勾")) {
					Intent intent = new Intent(MainActivity.this,
							SecondActivity.class);
					startActivity(intent);
					Toast.makeText(MainActivity.this, "已识别", Toast.LENGTH_SHORT)
					.show();
				} else {
					Toast.makeText(MainActivity.this, "名字不匹配",
							Toast.LENGTH_SHORT).show();
				}
			} else {
				Toast.makeText(MainActivity.this, "无法识别", Toast.LENGTH_SHORT)
				.show();
			}
		}

最后别忘了解绑监听:

protected void onDestroy() {
		mGov.removeOnGesturePerformedListener(this);
		super.onDestroy();
	}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI