Parameter interpretation of Viewpager sliding monitoring

Source: Internet
Author: User

Viewpager.setonpagechangelistener (New Onpagechangelistener () {                                     @Override public                   void onpageselected (int Select) {                         //TODO auto-generated method Stub                         Log. D ("DML", "Onpageselected:::::select ============" + Select);  c4/>}                                     @Override public                   void onpagescrolled (int positon, float arg1, int arg2) {                         //TODO auto-generated method Stub                         Log. D ("DML", "onpagescrolled:::::p osition =" + Positon);                   }                                     @Override public                   void Onpagescrollstatechanged (int.) {                         //TODO auto-generated method Stub                         Log. D (" DML "," onpagescrollstatechanged:::::state = "+ state);                   }             );



1. position is always the index of the first interface from left to right in the current interface, regardless of whether you are sliding so that there is no sliding at first onpagescrolled will also be called once, and position= 0. Sliding is actually divided into two processes: first the finger drive Viewpager slide, then the finger left the screen Viewpager will handle (either rebound or swipe to the next interface), the whole process onpagescrolled will be callback, Of course, position will always change .
2. the onpagescrollstatechanged will be recalled three times in a single swipe, in order 1 > 2 > 0 where 2 is the finger left the screen, the sliding event is successful, onpageselected must be in this 2 step after the execution, and only the current interface changes only callback, assignment bit the current interface index, so rebound onpageselected it will not callback
3. To determine which way the user slides, it should be judged with two conditions: the current interface int index, sliding position. For example: currently in the second interface, then int index = 1, at this time position = 1, the user starts to slide to the first interface POS Ition immediately becomes 0(because the first interface has been leaked) if you are sliding toward the third interface, position will remain at 1 (because the second interface is not completely hidden) until the third interface is completely sliding position=2 good, Now continue to the left slide because has been to the right of the row is not moving so position at this time has been maintained 2, the same in the first interface right sliding position will remain as 0

Parameter interpretation of Viewpager sliding monitoring

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.