A problem occurs when you use Gallery to display images. That is, the sliding speed is too fast. A few images are swiped each time. How can this problem be solved?
1. Directly inherit Grallery, override the onFling method, and return the value false.
[Java]
@ Override
Public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY ){
Return false;
}
2. The onFling method is also rewritten.
[Java]
Private boolean isScrollingLeft (MotionEvent e1, MotionEvent e2 ){
Return e2.getX ()> e1.getX ();
}
@ Override
Public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY ){
// E1 is the pressed event, and e2 is the lifted event
Int keyCode;
If (isScrollingLeft (e1, e2 )){
KeyCode = KeyEvent. KEYCODE_DPAD_LEFT;
} Else {
KeyCode = KeyEvent. KEYCODE_DPAD_RIGHT;
}
OnKeyDown (keyCode, null );
Return true;
}
From LonelyRoamer's column