[英]MotionEvent.ACTION_UP is not called
i have a problem with an OnSwipeImageListener
(implements OnTouchListener
). 我对
OnSwipeImageListener
(实现OnTouchListener
)有问题。 I use the OnSwipeImageListener
in two activities. 我在两个活动中使用
OnSwipeImageListener
。
On the one activitiy on the ImageView
is the OnTouchListener
and an OnClickListener
and on the other activity on the ImageView
is only the OnTouchListener
. 在
ImageView
上的一个活动是OnTouchListener
和OnClickListener
,在ImageView
上的另一活动仅是OnTouchListener
。
If i change return v. onTouchEvent(event)
to true
under the MotionEvent.ACTION_DOWN
then the OnClickListener
on the first activity doesn't work and in this way the Swipe of ImageView
on the second activity doesn't work. 如果我改变返回诉
onTouchEvent(event)
到true
下MotionEvent.ACTION_DOWN
那么OnClickListener
上的第一个活动不能正常工作,并以这种方式轻扫ImageView
第二活动不起作用。 I debugged some times and see that MotionEvent.ACTION_UP
is never called. 我进行了一些调试,发现从未调用
MotionEvent.ACTION_UP
。
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
dX = event.getX();
dY = event.getY();
return v.onTouchEvent(event);
case MotionEvent.ACTION_UP:
uX = event.getX();
uY = event.getY();
float deltaX = dX - uX;
float deltaY = dY - uY;
// horizontal
if(Math.abs(deltaX) > MIN_DISTANCE) {
//Left to right
if(deltaX < 0) {
this.onLeftToRight();
return v.onTouchEvent(event);
} else if (deltaX > 0) {
this.onRightToLeft();
return v.onTouchEvent(event);
}
else {
//Swipe too short
return v.onTouchEvent(event);
}
}
// vertical
if (Math.abs(deltaY) > MIN_DISTANCE) {
if(deltaY < 0) {
this.onTopToBottom();
return v.onTouchEvent(event);
} else if (deltaY > 0) {
this.onBottomToTop();
return v.onTouchEvent(event);
}
else {
//Swipe too short
return v.onTouchEvent(event);
}
}
}
return v.onTouchEvent(event);
}
If you want to get the ACTION_UP, you should hijack the ACTION_DOWN. 如果要获取ACTION_UP,则应劫持ACTION_DOWN。
Instead of returning " v.onTouchEvent(event)
", return " true
" when you are just handling the ACTION_DOWN. 当您仅处理ACTION_DOWN时,不返回“
v.onTouchEvent(event)
”,而返回“ true
”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.