qrobot开发总结之android手势识别

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);

大功告成,快试试吧!



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值