Android Viewpager Onpagechangelistener Interface

Source: Internet
Author: User

Project in the use of Viewpager, generally to do something when the interface sliding, Android has a special status callback interface Onpagechangelistener.

/**
* Callback interface for responding-changing state of the selected page.
*/
Public interface Onpagechangelistener {

/**
* This method was invoked when the current page was scrolled, either as part
* of a programmatically initiated smooth scroll or a user initiated touch scroll.
*
* @param position Position index of the first page currently being displayed.
* Page position+1 would be visible if positionoffset is nonzero.
* @param positionoffset Value from [0, 1] indicating the offset from the page at position.
* @param positionoffsetpixels Value in pixels indicating the offset from position.
*/
public void onpagescrolled (int position, float positionoffset, int positionoffsetpixels);

/**
* This method is invoked when a new page becomes selected. Animation is not
* Necessarily complete.
*
* @param position Position index of the new selected page.
*/
public void onpageselected (int position);

/**
* Called when the scroll state changes. Useful for discovering when the user
* Begins dragging, when the pager was automatically settling to the current page,
* or when it is fully stopped/idle.
*
* @param state, the new scroll state.
* @see Viewpager#scroll_state_idle
* @see viewpager#scroll_state_dragging
* @see viewpager#scroll_state_settling
*/
public void onpagescrollstatechanged (int.);
}

The introduction to Viewpager Onpagechangelistener in the SDK is as above. Publicvoid onpagescrolled ( int  position,float Positionoffset, int Positionoffsetpixels);Position: Current page numberPositionoffset page Offset (percentage) increments when you swipe to the right and decrements when you swipe left. positionoffsetpixels page pixel offsetIncrements when you swipe right, and decrements when you swipe left. Public void onpageselected (int position)Position: The currently selected page number  Public void Onpagescrollstatechanged (int.)state: The status of the page when it is sliding. Three states are defined in Viewpager.class, distributed as:


/**
* Indicates that the pager are in a idle, settled state. The current page
* is fully in view and no animation are in progress.
*/
public static final int scroll_state_idle = 0;

/**
* Indicates that the pager was currently being dragged by the user.
*/
public static final int scroll_state_dragging = 1;

/**
* Indicates that the pager are in the process of settling to a final position.
*/
public static final int scroll_state_settling = 2;

 Scroll_state_idle: A value of 0 indicates that the current page is selected. scroll_state_dragging: A value of 1 indicates that the current page is being dragged. scroll_state_setting: A value of 2 indicates that the current page is being dragged and is not yet in the selected state.  In the project use, you can get the offset of the page in onpagescrolled to set the sliding distance. in onpagestatechanged, the related logic is processed through the state of the page.

Android Viewpager Onpagechangelistener Interface

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.