Android Viewpager Slide Event Tutorial

Source: Internet
Author: User

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

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.