当前位置: 代码迷 >> Android >> 怎么检测多个指头scroll
  详细解决方案

怎么检测多个指头scroll

热度:87   发布时间:2016-04-28 06:52:14.0
如何检测多个指头scroll
如何检测多个指头的滑动、按下等

//在layout上做gesture
layout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
handleTouch(event);
return true;
}
});

private void handleTouch(MotionEvent event) {
int pointerCount = event.getPointerCount();
int action = event.getActionMasked();
operande1.setText("" + (action == MotionEvent.ACTION_SCROLL));
}


这里,是一个touch的listener 所以action只可能是UP啊DOWN啊 action永远不可能是SCROLL

我想检测多个指头的gesture,比如两个指头的longtouch 或者三个指头的scroll
怎么做??

谢大神
------解决方案--------------------
在onTouchEvent(MotionEvent event)方法里面获取多个指头的index和actionCode,以此来判断是哪个手指头做了动作。
//获得手指的数量
int count=event.getPointerCount();
int action=event.getAction();
int index=(action&MotionEvent.ACTION_POINTER_INDEX_MASK)>>MotionEvent.ACTION_POINTER_INDEX_SHIFT; //获取指针索引
int actionCode=action&MotionEvent.ACTION_MASK;//获取动作编码
------解决方案--------------------
你可以重写这个方法,利用我上面的答复,获取的actionCode为0时,是手指按下,1:手指抬起,2:手指移动。
  相关解决方案