Tou 4000 chSlop,Velocity,GestureDector
2016-03-04 10:06
232 查看
TouchSlop
系统所能识别出的被认为是滑动的最小距离,即当手指滑动的距离没有超过该最小距离,系统不认为使用者进行了滑动.该值会因为设备的不同而不同.通过下面的方法即可获得该常量值.
ViewConfiguration.get(getContext()).getScaledTouchSlop();
Velocity
速度追踪,用于追踪手指在滑动过程中的速度,包括水平和竖直方向的速度.
使用方法:在view的onTouchEvent方法中.
@Override
public boolean onTouchEvent(MotionEvent event) {
VelocityTracker obtain = VelocityTracker.obtain();
obtain.addMovement(event);
obtain.computeCurrentVelocity(1000); //该1000是个毫秒值,代表要计算出在1秒以内的速度值
float xVelocity = obtain.getXVelocity();
float yVelocity = obtain.getYVelocity();
Log.e("MC", xVelocity+":"+yVelocity);
obtain.clear();
obtain.recycle();//如果不使用了,必须回收
}上面就可以获取到横竖方向上的速度.
GestureDetector
手势检测,用于辅助检测用户的单击,滑动,长按,双击等行为.
使用方法:先创建GestureDector对象,并实现OnGestureListener接口.
@Override
public boolean onTouchEvent(MotionEvent event) {
GestureDetector detector = new GestureDetector(this,this); <span style="white-space:pre"> </span> //创建GestureDector对象,
detector.setIsLongpressEnabled(false);<span style="white-space:pre"> </span>//该方法可以解决长按屏幕后无法拖动的现象.
boolean onTouchEvent = detector.onTouchEvent(event);<span style="white-space:pre"> </span>//接管了目标view的onTouchEvent方法
return onTouchEvent;
}由于创建GestureDector对象的时候让该Acitivity页面实现了OnGestureListener接口,所以我们就可以在回调的接口方法里面去做我们自己想到的实现.
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
// TODO Auto-generated method stub
float x = e1.getX();
float x2 = e2.getX();
if (x2-x>200) {
finish();
}
return true;
}我实现了其中一个滑动的方法,当判断右滑的距离超过了200个像素点,就将当前页面给finish掉.
系统所能识别出的被认为是滑动的最小距离,即当手指滑动的距离没有超过该最小距离,系统不认为使用者进行了滑动.该值会因为设备的不同而不同.通过下面的方法即可获得该常量值.
ViewConfiguration.get(getContext()).getScaledTouchSlop();
Velocity
速度追踪,用于追踪手指在滑动过程中的速度,包括水平和竖直方向的速度.
使用方法:在view的onTouchEvent方法中.
@Override
public boolean onTouchEvent(MotionEvent event) {
VelocityTracker obtain = VelocityTracker.obtain();
obtain.addMovement(event);
obtain.computeCurrentVelocity(1000); //该1000是个毫秒值,代表要计算出在1秒以内的速度值
float xVelocity = obtain.getXVelocity();
float yVelocity = obtain.getYVelocity();
Log.e("MC", xVelocity+":"+yVelocity);
obtain.clear();
obtain.recycle();//如果不使用了,必须回收
}上面就可以获取到横竖方向上的速度.
GestureDetector
手势检测,用于辅助检测用户的单击,滑动,长按,双击等行为.
使用方法:先创建GestureDector对象,并实现OnGestureListener接口.
@Override
public boolean onTouchEvent(MotionEvent event) {
GestureDetector detector = new GestureDetector(this,this); <span style="white-space:pre"> </span> //创建GestureDector对象,
detector.setIsLongpressEnabled(false);<span style="white-space:pre"> </span>//该方法可以解决长按屏幕后无法拖动的现象.
boolean onTouchEvent = detector.onTouchEvent(event);<span style="white-space:pre"> </span>//接管了目标view的onTouchEvent方法
return onTouchEvent;
}由于创建GestureDector对象的时候让该Acitivity页面实现了OnGestureListener接口,所以我们就可以在回调的接口方法里面去做我们自己想到的实现.
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
// TODO Auto-generated method stub
float x = e1.getX();
float x2 = e2.getX();
if (x2-x>200) {
finish();
}
return true;
}我实现了其中一个滑动的方法,当判断右滑的距离超过了200个像素点,就将当前页面给finish掉.
相关文章推荐
- 如何安装nginx第三方模块
- nginx禁止IP直接访问可能禁止非本…
- Nginx中的rewrite指令
- Nginx配置性能优化
- linux中的 tar命令的 -C…
- Linux下chkconfig命令详解
- Nginx 开启Gzip压缩的方法(非…
- Nginx Location配置总结
- Nginx Cache方面的设置
- Nginx 单IP下 配置多个s…
- 关于 Nginx 499 和…
- Nginx 用log_format设置日志格式
- linux sed命令详解
- CentOS 静态IP分配,提示Error, some other host already uses address解决办法
- linux
- linux下去掉文件中^M的方法
- shell中的多进程【并发】转
- 使用socket方式连接Nginx优化php-f…
- CentOS6.5安装Docker(转)
- Linux不能上网ping:unknown h…