Android Gallery slides too fast

Source: Internet
Author: User

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.