When I was working on a project, I used Gallery to display images. One problem was that the slide was too fast. Every time I made a slight image, I slide a few images. How can I solve this problem? After searching, the following solution is available:
1. Customize Gallery to override the onFling Method
Public class UGallery extends Gallery {
Public UGallery (Context context, AttributeSet attrs ){
Super (context, attrs );
}
Private boolean isScrollingLeft (MotionEvent e1, MotionEvent e2 ){
Return e2.getX ()> e1.getX ();
}
@ Override
Public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX,
Float velocityY ){
Int keyCode;
If (isScrollingLeft (e1, e2 )){
KeyCode = KeyEvent. KEYCODE_DPAD_LEFT;
} Else {
KeyCode = KeyEvent. KEYCODE_DPAD_RIGHT;
}
OnKeyDown (keyCode, null );
Return true;
}
}
2. Use custom com. soft. userctrl. UGallery in the layout File
<Com. soft. userctrl. UGallery android: layout_width = "fill_parent" android: spacing = "50dip"
Android: layout_height = "fill_parent" android: id = "@ + id/isMain">
</Com. soft. userctrl. UGallery>
3. Use UGallery like Gallery in the code.
Excerpt from: spiritual pure earth column