case MotionEvent.ACTION_DOWN: if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } mPrivateFlags |= PREPRESSED; mHasPerformedLongPress = false; postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());//开始延迟线程检测触摸点移动没 break;
如果没有移动,则会开启一个延迟线程回调onLongClick()方法:
private final class CheckForTap implements Runnable { public void run() { mPrivateFlags &= ~PREPRESSED; mPrivateFlags |= PRESSED; refreshDrawableState(); if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { postCheckForLongClick(ViewConfiguration.getTapTimeout());//开启延迟线程回调onLongClick()方法 } } }
剩下来就和按键长按一样的处理了。在其中要注意二个参数:
ViewConfiguration.getTapTimeout() 是用于检测触摸点有没有移动的时间,默认为115毫秒