[英]onInterceptTouchEvent's ACTION_UP and ACTION_MOVE never gets called
Log is never logging ACTION_UP or ACTION_MOVE (which i removed from the code example for shortening) 日志永远不会记录ACTION_UP或ACTION_MOVE (出于缩短起见 ,我从代码示例中删除了它们)
Here is my shorten version of the code: 这是我的简化代码版本:
public class ProfileBadgeView extends LinearLayout {
Activity act;
public ProfileBadgeView(Context context) {
super(context);
}
public ProfileBadgeView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ProfileBadgeView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void initView(Activity act) {
//..init
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
logIntercept("ACTION DOWN");
} else if (ev.getAction() == MotionEvent.ACTION_UP) {
logIntercept("ACTION_UP");
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
return true;
}
private void logIntercept(Object obj) {
Log.i(this.getClass().getSimpleName() + " INTERCEPT :", obj.toString());
}
}
Your onInterceptTouchEvent
method is not called after ACTION_DOWN
event because you return true
in onTouchEvent
method. 在
ACTION_DOWN
事件之后不会调用您的onInterceptTouchEvent
方法,因为您在onTouchEvent
方法中返回true
。 So all the other events are sent in onTouchEvent
and not in onInterceptTouchEvent
any more: 因此,所有其他事件都在
onTouchEvent
中发送,而不再在onInterceptTouchEvent
中发送:
Using this function takes some care, as it has a fairly complicated interaction with View.onTouchEvent(MotionEvent), and using it requires implementing that method as well as this one in the correct way.
使用此函数需要格外小心,因为它与View.onTouchEvent(MotionEvent)的交互非常复杂,并且使用它需要以正确的方式实现该方法以及该方法。 Events will be received in the following order:
将按照以下顺序接收事件:
You will receive the down event here.
您将在此处收到下降事件。 The down event will be handled either by a child of this view group, or given to your own onTouchEvent() method to handle;
down事件将由该视图组的子项处理,或由您自己的onTouchEvent()方法处理; this means you should implement onTouchEvent() to return true, so you will continue to see the rest of the gesture (instead of looking for a parent view to handle it).
这意味着您应该实现onTouchEvent()以返回true,因此您将继续查看其余手势(而不是寻找父视图来处理该手势)。 Also, by returning true from onTouchEvent(), you will not receive any following events in onInterceptTouchEvent() and all touch processing must happen in onTouchEvent() like normal .
此外, 通过从onTouchEvent()返回true,您将不会在onInterceptTouchEvent()中接收到任何后续事件,并且所有触摸处理都必须像正常一样在onTouchEvent()中进行 。
http://developer.android.com/reference/android/view/ViewGroup.html#onInterceptTouchEvent(android.view.MotionEvent) http://developer.android.com/reference/android/view/ViewGroup.html#onInterceptTouchEvent(android.view.MotionEvent)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.