1:首先我自定义一个LinearLayout,和TextView,重写它们的onInterceptTouchEvent和onTouchEvent方法,观察它们都返回值。
前者onInterceptTouchEvent是在ViewGroup里面定义的,android里的布局类一般都会继承此类。
onInterceptTouchEvent是用于拦截手势事件的,每个手势事件都会先调用onInterceptTouchEvent。
onTouchEvent同样也是在view中定义的一个方法。处理传递到view 的手势事件。手势事件类型包括ACTION_DOWN,ACTION_MOVE,ACTION_UP,ACTION_CANCEL等事件。

其实在Layout中onInterceptTouchEvent默认返回值事false,这样就能将touch事件传递到view控件。先调用ACTION_DOWN事件,当onTouchevent里返回值是true的时候,onTouchevent回继续调用ACTION_UP事件,如果onTouchevent里返回值是false,那么onTouch只会调用ACTION_DOWN而不调用ACTION_UP.
下面看打印。

![这里写图片描述](https://img-blog.csdn.net/20160718200737426)

从这里我们看出,系统默认的Myview的OntouhchEvent返回false,只消费了actiond_down事件,这样后面的action_up事件并没有消费。
当我们把Myview的OntoucheEvent返回true时,当我们按下去再松手我们会发现两个事件,action_down,action_up都被消费了

而且当我们移动的时候,action_move也都被消费了

07-18 20:14:09.862 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:09.862 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_DOWN...false
07-18 20:14:09.862 26916-26916/com.example.zew.demo2 V/ViewRootImpl: finishMotionEvent: handled = true stage=10: View Post IME stage eventTime = 39775261 title= com.example.zew.demo2/com.example.zew.demo2.MainActivity
07-18 20:14:10.515 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:10.516 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:14:10.532 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:10.532 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:14:10.549 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:10.549 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:14:10.566 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:10.566 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:14:10.584 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:10.585 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:14:10.600 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:10.601 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:14:10.616 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:10.617 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:14:10.633 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:10.634 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:14:10.650 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:10.651 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:14:10.667 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:10.667 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:14:10.818 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:10.818 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:14:10.825 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:10.825 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:14:10.825 26916-26916/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:14:10.825 26916-26916/com.example.zew.demo2 E/tag: Myview....ACTION_UP....false

另外我实验了当action_move返回false的时候,后面的action_move.action_up都是可以响应的,

07-18 20:17:20.961 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:20.961 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_DOWN...false
07-18 20:17:20.962 30633-30633/com.example.zew.demo2 V/ViewRootImpl: finishMotionEvent: handled = true stage=10: View Post IME stage eventTime = 39966360 title= com.example.zew.demo2/com.example.zew.demo2.MainActivity
07-18 20:17:21.617 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.617 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.634 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.634 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.650 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.650 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.667 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.667 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.684 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.684 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.701 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.701 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.717 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.718 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.734 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.734 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.751 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.751 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.768 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.768 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.784 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.784 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.801 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.801 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.818 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.818 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.884 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.884 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....false
07-18 20:17:21.884 30633-30633/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:17:21.884 30633-30633/com.example.zew.demo2 E/tag: Myview....ACTION_UP....false

所以我们的action_down是否消费会直接影响后面,action_move,action_up。

下面我们通过看源码可以得知,dispatcherTouchevent里 面通过onTonchListener.ontouch(ev)返回的值决定view的onTonch能否被执行,假如返回false,那么会走onToucheEvent,假如返回true的话不会走onTouchEvent
下面实验,返回true的情况

       super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ll = (Mylinearlayout) findViewById(R.id.ll);mv = (Myview) findViewById(R.id.mv);mv.setOnTouchListener(new View.OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {return true;}});}
打印结果

07-18 20:27:22.500 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:22.500 5710-5710/com.example.zew.demo2 V/ViewRootImpl: finishMotionEvent: handled = true stage=10: View Post IME stage eventTime = 40567898 title= com.example.zew.demo2/com.example.zew.demo2.MainActivity
07-18 20:27:23.184 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.201 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.218 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.234 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.251 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.268 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.285 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.301 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.318 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.335 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.354 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.371 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.388 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.405 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.421 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.438 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.455 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.472 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.489 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.505 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.522 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.539 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.640 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.656 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.672 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false
07-18 20:27:23.673 5710-5710/com.example.zew.demo2 E/tag: Mylinearlayout…..onInterceptTouchEvent….false

可以看出并没有走onTouchEvent。

当我们的onToucheListener.ontouch(ev)返回false以后,就会走onTouchEvent。假如这时候我们的OntouchEvent,的action_up返回true,则消费事件,后面的action_move,up都会执行。看log

07-18 20:48:02.283 16548-16548/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:48:02.283 16548-16548/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:48:02.283 16548-16548/com.example.zew.demo2 E/tag: Myview....ACTION_DOWN...true
07-18 20:48:02.283 16548-16548/com.example.zew.demo2 V/ViewRootImpl: finishMotionEvent: handled = true stage=10: View Post IME stage eventTime = 41807682 title= com.example.zew.demo2/com.example.zew.demo2.MainActivity
07-18 20:48:02.568 16548-16548/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:48:02.568 16548-16548/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:48:02.568 16548-16548/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....true
07-18 20:48:02.584 16548-16548/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:48:02.584 16548-16548/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:48:02.584 16548-16548/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....true
07-18 20:48:02.601 16548-16548/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:48:02.601 16548-16548/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:48:02.601 16548-16548/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....true
07-18 20:48:02.618 16548-16548/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:48:02.618 16548-16548/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:48:02.618 16548-16548/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....true
07-18 20:48:02.635 16548-16548/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:48:02.635 16548-16548/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:48:02.635 16548-16548/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....true
07-18 20:48:02.651 16548-16548/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:48:02.651 16548-16548/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:48:02.651 16548-16548/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....true
07-18 20:48:02.668 16548-16548/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:48:02.668 16548-16548/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:48:02.668 16548-16548/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....true
07-18 20:48:02.685 16548-16548/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:48:02.685 16548-16548/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:48:02.685 16548-16548/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....true
07-18 20:48:02.692 16548-16548/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:48:02.692 16548-16548/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:48:02.692 16548-16548/com.example.zew.demo2 E/tag: Myview....ACTION_MOVE....true
07-18 20:48:02.693 16548-16548/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:48:02.693 16548-16548/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:48:02.693 16548-16548/com.example.zew.demo2 E/tag: Myview....ACTION_UP....true
07-18 20:48:02.693 16548-16548/com.example.zew.demo2 E/tag: Myview.....onClick....

注意最后才执行点击事件,onclick.这是为什么呢?
通过看源码我们得知:

public boolean onTouchEvent(MotionEvent event) {if (((viewFlags & CLICKABLE) == CLICKABLE ||(viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) {switch (event.getAction()) {case MotionEvent.ACTION_UP:boolean prepressed = (mPrivateFlags & PFLAG_PREPRESSED) != 0;if ((mPrivateFlags & PFLAG_PRESSED) != 0 || prepressed) {// take focus if we don't have it already and we should in// touch mode.boolean focusTaken = false;if (isFocusable() && isFocusableInTouchMode() && !isFocused()) {focusTaken = requestFocus();}if (prepressed) {// The button is being released before we actually// showed it as pressed.  Make it show the pressed// state now (before scheduling the click) to ensure// the user sees it.setPressed(true, x, y);}if (!mHasPerformedLongPress) {// This is a tap, so remove the longpress checkremoveLongPressCallback();// Only perform take click actions if we were in the pressed stateif (!focusTaken) {// Use a Runnable and post this rather than calling// performClick directly. This lets other visual state// of the view update before click actions start.if (mPerformClick == null) {mPerformClick = new PerformClick();}if (!post(mPerformClick)) {performClick();}}}if (mUnsetPressedState == null) {mUnsetPressedState = new UnsetPressedState();}if (prepressed) {postDelayed(mUnsetPressedState,ViewConfiguration.getPressedStateDuration());} else if (!post(mUnsetPressedState)) {// If the post failed, unpress right nowmUnsetPressedState.run();}removeTapCallback();}break;return true;}return false;}

再看看这个方法里performClick()里面做了什么?

public boolean performClick() {final boolean result;final ListenerInfo li = mListenerInfo;if (li != null && li.mOnClickListener != null) {playSoundEffect(SoundEffectConstants.CLICK);li.mOnClickListener.onClick(this);result = true;} else {result = false;}sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);return result;}

注意看那个performClick()方法,这个方法是在action_up手势后面执行的。所以最后在action_up响应后会响应点击事件。

看见没??第6行 li.mOnClickListener.onClick(this); 这个接口回调就是我们Button的 onClick事件。到此为止,我们从源码分析了Button事件分发过程
结论:dispatchTouchEvent—->onTouch—->onTouchEvent—–>onClick。并且如果仔细的你会发现,是在所有ACTION_UP事件之后才触发onClick点击事件。

那当我们ontouchlistener.ontouch()返回true的话会怎么样?

07-18 20:54:17.555 22194-22194/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:54:17.555 22194-22194/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:54:17.555 22194-22194/com.example.zew.demo2 V/ViewRootImpl: finishMotionEvent: handled = true stage=10: View Post IME stage eventTime = 42182953 title= com.example.zew.demo2/com.example.zew.demo2.MainActivity
07-18 20:54:17.779 22194-22194/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:54:17.779 22194-22194/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:54:17.796 22194-22194/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:54:17.796 22194-22194/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:54:17.813 22194-22194/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:54:17.813 22194-22194/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:54:17.830 22194-22194/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:54:17.830 22194-22194/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:54:17.846 22194-22194/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:54:17.846 22194-22194/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:54:17.863 22194-22194/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:54:17.863 22194-22194/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:54:17.880 22194-22194/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:54:17.880 22194-22194/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:54:17.888 22194-22194/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:54:17.889 22194-22194/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:54:17.889 22194-22194/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:54:17.889 22194-22194/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down

可以看出没有走onTouchEvent方法自然也没有o’clock点击事件。
那假如让我们ontouchlistener.ontouch()返回false,但是让action_up返回false,会不会响应点击事件。

修改一下` public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:

            Log.e("tag","Myview....ACTION_DOWN..."+super.onTouchEvent(event));return false;

// break;
case MotionEvent.ACTION_MOVE:
Log.e(“tag”,”Myview….ACTION_MOVE….”+super.onTouchEvent(event));
break;
case MotionEvent.ACTION_UP:
Log.e(“tag”,”Myview….ACTION_UP….”+super.onTouchEvent(event));
break;
case MotionEvent.ACTION_CANCEL:
Log.e(“tag”,”Myview….ACTION_CANCEL….”+super.onTouchEvent(event));
break;

    }return true;
}
07-18 20:58:16.075 23882-23882/com.example.zew.demo2 E/tag: Mylinearlayout.....onInterceptTouchEvent....false
07-18 20:58:16.075 23882-23882/com.example.zew.demo2 E/tag: Myview.....ontouch....action_down
07-18 20:58:16.075 23882-23882/com.example.zew.demo2 E/tag: Myview....ACTION_DOWN...true
07-18 20:58:16.075 23882-23882/com.example.zew.demo2 E/tag: Mylinearlayout.....onTouchEvent....false

从log,可以看出只响应了我们的action_down事件。后面的action_up没有响应,自然点击事件也就没有。。。

我们手指触碰屏幕都做了什么?相关推荐

  1. Android opengles 实现触碰屏幕,根据运动轨迹画直线的功能

    Android opengles 实现触碰屏幕,根据运动轨迹画直线的功能 目录 引言 第一步,先自己学会绘制一条固定坐标的直线 第二步,动态的绘制一条直线 第三步,坐标转换 第四步,绘制多条直线 代码 ...

  2. 用手指触碰电子,用心灵感受震荡

    ▲ 玻璃封装内的二极管 01二极管基本结构 ▲ 点二极管的内部结构 DIY FET/home-made transistor Scientific American June 1970 Homemad ...

  3. iOS--触碰响应UIResponder UIGestureRecognizer

    疯狂iOS讲义总结 一.在iOS中,触碰的响应是以响应者链的形式进行的.也就是说,当用户和某个控件交互时,该控件会成为第一响应者(First Responder),第一响应者作为响应者链的开始,交互交 ...

  4. UGUI射线检测或触碰检测

    在开发移动端时,往往需要触碰UI实现与UI的交互,要是使用射线检测机制,这时候问题来了,会发现与UI交互不起作用,这是为什么呢? 解决方法有挺多的,以下是个人常用的两种解决办法: 方法一: 首先,要使 ...

  5. Android源码解析触碰机制

    分发  dispatchTouchEvent  触碰屏幕时会触发的view方法,原理需要看更深层次的源码,这里可以理解为入口 拦截  onInterceptTouchEvent 消费  onTouch ...

  6. html5 移动端的手指触屏事件

    用户在移动端浏览H5的时候,会使用手指进行一连串的操作,单击.双击.上拉.下拉等等一系列操作,这里主要针对touch事件进行一些简单的介绍: 用户从手指触碰到屏幕到手指离开屏幕这中间,会触发一系列的t ...

  7. scratch做简单跑酷游戏_Scratch(七)篇外.用小动画和触碰能做大型游戏?

    有一些同学私信我,前几章节学会角色.舞台和动画,然后再加上第七章的触碰,这些看上去挺简单,但是普遍怀疑这些基础知识的实用性,都想快速进入到编程环节里面. 其实scratch编程不复杂,复杂的是各个基础 ...

  8. 【国企笔试】264、如下图所示,装有水的烧杯放在天平一端,另一端放置砝码使天平平衡,此时再放入一手指在水中,若手指完全静止在水中且没有触碰烧杯壁和烧杯底部,且水也没有溢出,那么这时天平的状态是:

    264.如下图所示,装有水的烧杯放在天平一端,另一端放置砝码使天平平衡,此时再放入一手指在水中,若手指完全静止在水中且没有触碰烧杯壁和烧杯底部,且水也没有溢出,那么这时天平的状态是: A.继续保持平衡 ...

  9. qt读取文件里的数据并做折线图 并鼠标触碰显示

    qt读取文件里的数据并做折线图 并鼠标触碰显示 void MainWindow::chartShow1() {strText =ui->dateTimeEdit->text(); //传递 ...

最新文章

  1. Securecrt连接linux时速度特别慢的解决办法
  2. php umount强制,php foreach 參數強制類型轉換的問題 | 學步園
  3. Simulink之门极关断晶闸管(GTO)
  4. 发电机机房设计规范_民用建筑变电所等机房设置的几点建议
  5. 二十、K8s集群设置2- HTTPS-CFSSL
  6. Python新手写出漂亮的爬虫代码1——从html获取信息
  7. 阿里云网站备案时短信核验遇到问题解决办法
  8. 远程网络教学系统用例图
  9. R语言中的apply(),lapply(),sapply(),tapply()函数以及示例
  10. 如何实现前后端分离开发
  11. 最详BF算法和KMP算法
  12. 玩转字符串篇--代码自动生成,解放双手,android音视频开发
  13. 晚上思考人生千条路,白天走原路
  14. NSIS 头文件介绍_TextFunc.nsh(2)
  15. Redis~集群(分布理论、一致性哈希分区、虚拟槽分区、节点握手、集群通信、集群伸缩、请求路由、故障转移、集群维护)
  16. 四、全国计算机三级数据库考试——操作题(6—10套)
  17. Fedora17下的hadoop-1.0.4系统配置
  18. 三国群英传服务器未响应,《三国群英传2》近期服务器不稳定问题说明
  19. 一次开发中并发删除插入死锁分析记录
  20. 每次打开计算机是快速访问,如何关闭Win10电脑的快速访问功能

热门文章

  1. cad 中的计算机在哪里打开,CAD计算器如何使用?
  2. 网页认证上网服务器无响应,portal认证失败,网络故障或者portal服务器没有响应排查方法...
  3. java jpeg rpg_史上最骚RPG制作第三期 java端数据的插入和查询
  4. 电池高压安全注意事项
  5. 内网计算机安全使用规则,局域网网络安全注意事项
  6. 调用函数----如何在主函数调用子函数
  7. 大厂对学历的要求是什么?如果学历不够,拿什么来凑?
  8. 如何限制一台电脑只能登陆一个QQ帐号
  9. Win10/UWP 扫描二维码
  10. 认识css长度单位 px % em rem vh vw