Android手势库
分类: 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. 使用手势


1)将手势库放在工程中
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();//保存在后一次的屏幕图          }       });

更多相关文章

  1. Android通过onDraw实现在View中绘图操作
  2. Android(安卓)访问权限设置记录-存档留着有用!
  3. APP横竖屏不切换,不重走生命周期
  4. Android通过RSA加密解密实现License
  5. android rootfs
  6. Android——编译odex保护
  7. android:windowSoftInputMode属性使用
  8. 调用Android系统设置中的Intent
  9. Unbuntu下Android(安卓)studio报Unable to recreate missing deb

随机推荐

  1. Android(安卓)NDK开发:NDK概览
  2. 精通Android
  3. Android面经总结
  4. Android常用控件之悬浮窗
  5. Android(安卓)编辑框(EditText)属性学习
  6. Android(安卓)Studio 将引用第三方jar包,
  7. 第一个android应用程序
  8. [Android][获取Android设备唯一标识]
  9. vlc android 截图和录制视频(vlc0.9.9)
  10. JS判断客户端类型 iOS / Android(安卓)/