Android development and learning-Explanation of ViewPager sliding events

Source: Internet
Author: User

Android ViewPager sliding Event Description

When I was working on a project today, I made a small research on viewPager page slide events:

First, ViewPager uses OnPageChangeListener to process sliding events.

OnPageChangeListener: (onPageScrollStateChanged, onPageScrolled, onPageSelected)

OnPageScrollStateChanged (int arg0), which is called when the status changes, where arg0

There are three States (0, 1, 2 ). Arg0 = 1 of the hour is sliding, arg0 = 2 of the hour of the implied sliding is completed, arg0 = 0 of the hour of the implied nothing.

When the page starts to slide, the order of the three States is (1, 2, 0), as shown below:

Code block when viewPager status changes:

Print result:

OnPageScrolled (int arg0, float arg1, int arg2), this method is called when the page is sliding. This method is always obtained until the sliding is stopped.

Call. The meanings of the three parameters are as follows:

Arg0: Current page, and the page you click to slide

Arg1: percentage of current page offset

Arg2: The pixel position of the current page offset

(See the official website: http://docs.eoeandroid.com/reference/android/support/v4/view/ViewPager.OnPageChangeListener.html#onPageScrolled (int, float, int ))

The demo is as follows:

Code for Page scrolling:

Log printing:

OnPageSelected (int arg0): This method is called after the page is redirected, and arg0 is the Position (Position number) of the selected page ).

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.