qrobot开发总结之android手势识别
来源:互联网 发布:gm300写频软件 编辑:程序博客网 时间:2024/04/30 08:49
1、实现两个接口
implements OnTouchListener, OnGestureListener
onTouchListener接口只有一个方法
public abstract boolean onTouch (View v, MotionEvent event)
onGestureListener接口有以下方法
public abstract boolean onDown (MotionEvent e)
public abstract boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
public abstract void onLongPress (MotionEvent e)
public abstract boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
public abstract void onShowPress (MotionEvent e)
public abstract boolean onSingleTapUp (MotionEvent e)
处理手势识别只需要复写onFiing方法,其中由e1.getX()和e1.getY()可以得到按下屏幕时的坐标,
同样可以由e2得到离开屏幕时的坐标,比较两个坐标的相对位置,可以判断手指划过屏幕的方向。
qrobot开发过程中只用到从左向右或从右向左的手势识别。
2、GestureDetector类
初始化:
private GestureDetector gestureDetector = null;
gestureDetector = new GestureDetector(this);gestureDetector.setIsLongpressEnabled(true);
注意第2句
在onTouch方法中
public boolean onTouch(View v, MotionEvent event) {return gestureDetector.onTouchEvent(event);}
3、给控件添加监听器
在qrobot开发中监听器是加在一个空白的textview上的
textView.setFocusable(true); textView.setClickable(true); textView.setLongClickable(true); textView.setOnTouchListener(this);
大功告成,快试试吧!
- qrobot开发总结之android手势识别
- qrobot开发总结之android语音识别
- qrobot开发总结之android完全退出程序
- Android开发之手势识别
- Android开发之手势识别
- Android开发之手势识别
- android开发之手势识别
- iOS开发之手势识别 总结
- Android应用开发之手势识别
- android手势识别总结
- android之手势识别
- android之手势识别
- android之手势识别
- Android之手势识别
- Android 之手势识别
- Android之手势识别
- qrobot开发总结之利用第三方TTS软件开发中文TTS
- iOS开发之手势识别
- 下面这个函数TX_memset4是什么意思了?
- 详解VS2005模块定义文件(.def)
- 学生类 总分 平均分 最高分 和 最低分的 java代码
- 布局的控件存在,但代码中无法实例化
- JS面向对象问题初步解析
- qrobot开发总结之android手势识别
- 基于REST架构的Web Service设计
- jQuery学习点滴
- android模拟器无法启动 找不到设备
- div+css 兼容ie6 ie7 ie8 ie9和FireFox Chrome等浏览器方法
- android调试技巧
- JAVA实现打开文件对话框(可以指定所需打开文件的格式)
- CEdit的"\r\n"不换行和自动换行问题
- haha