First of all, Viewpager is used when handling sliding events Onpagechangelistener
Onpagechangelistener This interface requires the implementation of three methods: (Onpagescrollstatechanged,onpagescrolled, onpageselected)
onpagescrollstatechanged (int arg0), this method is called when the state changes, where arg0 this parameter
There are three states (0,1,2). Arg0 ==1 When the time implied is sliding, arg0==2 the hour of the tacit slide is finished, arg0==0 of the hour implied nothing did.
When the page starts to slide, the three states change in order (1,2,0), as shown below:
code block when the Viewpager state changes:
Printing results:
onpagescrolled (int arg0,float arg1,int arg2), this method is called when the page is sliding, and this method returns until the slide is stopped .
Call. The meanings of three of these parameters are:
ARG0: The current page, and the page you clicked to swipe
Arg1: Percentage of current page offset
Arg2: The pixel position of the current page offset
(See official website: http://docs.eoeandroid.com/reference/android/support/v4/view/ViewPager.OnPageChangeListener.html# onpagescrolled (int, float, int))
The demo is as follows:
Page scrolling Time Code:
Log printing:
onpageselected (int arg0): This method is called after the page has been jumped, arg0 is the position (position number) of the page you are currently selecting.
Reprinted from http://blog.csdn.net/xipiaoyouzi/article/details/12121131
Android Viewpager Slide Event Tutorial