有两种实现方法:
1、通过view事件的传递机制,如果是连续点击,则拦截目标的点击事件
@Override public boolean dispatchTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { if (isFastDoubleClick()) { return true; } } return super.dispatchTouchEvent(ev); } long lastClickTime; public boolean isFastDoubleClick() { long time = System.currentTimeMillis(); long timeD = time - lastClickTime; if ( 0 < timeD && timeD < 500) { return true; } lastClickTime = time;
return false;}
2、只要在xml文件中的父容器总加入这样一行代码即可: android:splitMotionEvents=”false” 如在下面的LinearLayout中加入这行话,表示每一次只能点击LinearLayout其中的一个元素,点击了其他的元素是无效的。 android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/dp10" android:splitMotionEvents="false" android:background="@drawable/shape_frame_black" android:orientation="vertical" > 防止点击一个控件多次 这个我们只要加上一个标志位就可以了,判断前后2次的点击时间间隔是