Requirements: Viewpager display pictures, you need to double-click on the picture to zoom, when clicked on the bottom of the screen pop Popwindow, because the Android double-click Essence is two clicks, but do not want to trigger the click when the action, so on the internet a variety of search solutions, no results, After a while, found the following methods
1. Dispatchtouchevent method for overriding activity
1 @Override2 Public Booleandispatchtouchevent (Motionevent event) {3 4 if(event.getaction () = =Motionevent.action_down) {5Mdownx = (int) Event.getx ();6 if(Mfirsttoucheventtime = = 0) {7Mfirsttoucheventtime =event.getdowntime ();8}Else {9Mlasttoucheventtime =event.getdowntime ();Ten } One}Else if(event.getaction () = =motionevent.action_up) { AMUPX = (int) Event.getx (); - if(Math.Abs (MUPX-MDOWNX) < 30) { -LOG.D (TAG, "--->>" + math.abs (Mfirsttoucheventtime-mlasttoucheventtime)); the if(Math.Abs (Mfirsttoucheventtime-mlasttoucheventtime) <Constants.time_menu_display) { -Mfirsttoucheventtime = 0L; -Mlasttoucheventtime = 0L; - mscreenobsever.removemessages (constants.msg_menu_display); +}Else { - mscreenobsever.sendemptymessagedelayed (Constants.msg_menu_display, constants.time_menu_display);
+ } A}Else { atMfirsttoucheventtime = 0L; -Mlasttoucheventtime = 0L; - } - } - - return Super. Dispatchtouchevent (event); in}
Among them, Mfirsttoucheventtime and Mlasttoucheventtime are two long class variables, which are used to record the time of the occurrence of two action_down actions,constants.time_menu_display for a custom msg what. Mscreenobserver is a custom handler that is used to handle click events.
Handler class implementation of 2.mScreenObserver
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
private class ObseverOperateHandler
extends Handler {
@Override
public void handleMessage(Message msg) {
if (msg.what == Constants.MSG_MENU_DISPLAY) {
mFirstTouchEventTime = 0L;
mLastTouchEventTime = 0L;
if (mOperateMenuPopupWindow.isShowing()) {
mNotePopWindow.startDownAnimation();
mOperateMenuPopupWindow.dismiss();
}
else {
mNotePopWindow.startUpAnimation();
mOperateMenuPopupWindow.showAtLocation(findViewById(R.id.photoLayout), Gravity.BOTTOM,
0
,
0
);
}
}
super
.handleMessage(msg);
}
}
|
The if part is going to be in a single-hit deal.
3. As for the double-click to do things, you can normally implement Gesturedetector.ondoubletaplistener to deal with. You can find out how to do it online.
In addition the code of Constants.time_menu_display this time value, by various means to verify that the 350ms is more appropriate, that is, two-click Interval 350ms will be considered a double-click.