Android手势库
16lz
2022-05-19
Android手势库
分类: Android 2011-07-18 11:21 210人阅读 评论(0) 收藏 举报
1. 生成手势 (可参考自带的GestureBuilder)
1) Layout里面加上
3)当onGestureEndded调用时表明手势已经完成, 从overlay.getGesture中的到已经完成的手势
4)使用GestrureLibraries.from(path)得到GestureLibrary
2) 加载手势库
3)实现GestureOverlayView.OnGesturePerformedListener
4)覆写onGesturePerfromed, library.recognize(gesture), 就可以识别手势了
单划处理
首先生成手势库,用android中的自带例子生成。
并把生成的手势库,放入你要运行的android的项目的res目录下的raw中。
在xml中设置手势的触屏界面
加载手势库,
分类: Android 2011-07-18 11:21 210人阅读 评论(0) 收藏 举报
1. 生成手势 (可参考自带的GestureBuilder)
1) Layout里面加上
<android.gesture.GestureOverlayView android:id="@+id/gesture" android:layout_width="fill_parent" android:layout_height="fill_parent" />2)GestureOverlayView注册OnGestureListener实现onGesturesStarted, onGesture, onGestureEnded方法
3)当onGestureEndded调用时表明手势已经完成, 从overlay.getGesture中的到已经完成的手势
4)使用GestrureLibraries.from(path)得到GestureLibrary
5) 使用gesturelibrary.addGesture("xxx", gesture) 将gesture与字符串绑定
2. 使用手势
2) 加载手势库
3)实现GestureOverlayView.OnGesturePerformedListener
4)覆写onGesturePerfromed, library.recognize(gesture), 就可以识别手势了
单划处理
首先生成手势库,用android中的自带例子生成。
并把生成的手势库,放入你要运行的android的项目的res目录下的raw中。
在xml中设置手势的触屏界面
<android.gesture.GestureOverlayView android:id="@+id/gesture" android:layout_width="fill_parent" android:layout_height="fill_parent" />若设成
<android.gesture.GestureOverlayView android:id="@+id/gesture" android:layout_width="fill_parent" android:layout_height="fill_parent" />则报错。
加载手势库,
GestureLibrary library = GestureLibraries.fromRawResource(this,R.raw.gestures);//设置手势库路径library.load();//加载手势库得到手势屏幕
GestureOverlayView overlayView =(GestureOverlayView) this.findViewById(R.id.gesture);设置单笔手势监听器:
overlayView.addOnGesturePerformedListener(newGestureOverlayView.OnGesturePerformedListener(){ public void onGesturePerformed(GestureOverlayViewoverlay, Gesture gesture) { //用户写的手势与手势库对比,得到对比结果 ArrayList<Prediction> list=library.recognize(gesture); if(list!=null){ Prediction p = list.get(0);//取得最符合的手势结果 if(p.score>5){//对比度越大相似度越高 Toast.makeText(getApplicationContext(), p.name, 1).show(); } else{ Toast.makeText(getApplicationContext(), "匹配不成功", 1).show(); } } } });多划处理
在xml中设置手势的触屏界面<android.gesture.GestureOverlayView android:id="@+id/gesture" android:layout_width="fill_parent"android:layout_height="fill_parent"android:gestureStrokeType="multiple" <!-此句是设置使用多笔处理-> />将监听器该为
overlayView.addOnGestureListener(new OnGestureListener(){ @Override public void onGesture(GestureOverlayView overlay, MotionEventevent) { } public void onGestureCancelled(GestureOverlayViewoverlay, MotionEvent event) { } public void onGestureEnded(GestureOverlayViewoverlay, MotionEvent event) { } public void onGestureStarted(GestureOverlayViewoverlay, MotionEvent event) { gesture = overlay.getGesture();//保存在后一次的屏幕图 } });
更多相关文章
- Android通过onDraw实现在View中绘图操作
- Android(安卓)访问权限设置记录-存档留着有用!
- APP横竖屏不切换,不重走生命周期
- Android通过RSA加密解密实现License
- android rootfs
- Android——编译odex保护
- android:windowSoftInputMode属性使用
- 调用Android系统设置中的Intent
- Unbuntu下Android(安卓)studio报Unable to recreate missing deb