[英]Android Multi-Touch Not Responding
我正在尝试构建使用多点触控的应用程序。 我正在使用'getActionMasked()'
来获取当前动作,然后检查指针计数是否为两个。
但是代码却没有按我期望的那样工作。
我主要面临两个问题。
'MotionEvent.ACTION_UP'
未执行。 这是代码:
imgs.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent m) {
// TODO Auto-generated method stub
//Prevent false touch events
long now = System.currentTimeMillis();
if (lastTime > -1 && (now - lastTime) < threshold) {
// Return if a touch event was receive less than "threshold" time ago
return true;
}
lastTime = now;
switch(m.getActionMasked()){
case MotionEvent.ACTION_DOWN:
td = System.currentTimeMillis();
int pointerCount = m.getPointerCount();
if (pointerCount == 2){
//Do Work here. [Not Working]
}
return true;
case MotionEvent.ACTION_UP:
//Do Work here. [Not Working]
return true;
}
return arg0.onTouchEvent(m);
}
});
我不确定自己在做什么错。 期待对此有所帮助,并对我做错的事情有所澄清。
我认为setOnTouchListener仅适用于单指,因此您永远不会遇到两指事件。 您可以使用onTouchEvent(View v,MotionEvent e),
public class yourview extends view(
@Override
public boolean onTouchEvent(MotionEvent m) {
int pointerCount = m.getPointerCount();
switch (m.getAction() & MotionEvent.ACTION_MASK) {
//case
case MotionEvent.ACTION_POINTER_DOWN:
if (pointerCount == 2){
//do what you want here.
}
//case
}
return true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.