(Android Control) ViewPager introduction and instructions for use

Source: Internet
Author: User

1 ViewPagerImplemented FunctionsAnd actual running

The ViewPager class provides new effects of multi-interface switching. The new effect has the following features:

[1] One of the interfaces in A group is currently displayed.

[2] when a user slides between the left and right, the current screen displays the current interface and a part of the next interface.

[3] After sliding, the page automatically jumps to the selected page

 

The following is the implementation

 

2How to Use ViewPagerWidget

 

2.1Reference ViewPagerWidget

ViewPager comes from google's complementary component android-support-v13.jar, which is located in the androidSDK folder

Android-sdk-windows \ extras \ android \ compatibility \ v13

 

Reference android-support-v13.jar to a project

 

2.2Configuration page file

<Android. support. v4.view. ViewPager

Android: id ="@ + Id/viewPager1"

Android: layout_width ="Fill_parent"

Android: layout_height ="Fill_parent"

Android: layout_alignLeft ="@ + Id/textView1"

Android: layout_above ="@ Id/adLayout"

Android: layout_below ="@ Id/topText"

Android: layout_centerVertical ="True"/>

 

2.3SetViewPagerControl Adapter

The ViewPager adapter inherits from the PagerAdapter base class and implements the following four methods:

// Obtain the number of interfaces of the current form

Public int getCount ()

// Initialize the position page

Public Object instantiateItem (View collection, int position)

 

// Destroy the position page

Public void destroyItem (View collection, int position, Object view)

 

// Determine whether the interface is generated by the object

Public boolean isViewFromObject (View arg0, Object arg1)

 

3Initialize ViewPagerWidget

Initialize the adapter of the ViewPager Control

 

ViewPager1 = (ViewPager) findViewById (R. id.ViewPager1);

ViewPager1.setAdapter (NewImgPagerAdapter (This, Lists ));

 

Configure page change events for the adapter

ViewPager1

. SetOnPageChangeListener (NewOnPageChangeListener (){

// Select on the page

@ Override

Public VoidOnPageSelected (IntPosition ){

TopText. setText (String.ValueOf(Position + 1) + "/" + String.ValueOf(Lists. length ));

}

 

@ Override

Public VoidOnPageScrollStateChanged (IntState ){

}

 

@ Override

Public VoidOnPageScrolled (IntPosition,

FloatPositionOffset,IntPositionOffsetPixels ){

}

});

 

 

Appendix:

Android Market of science back words-Level 4 edition: http://static.apk.hiapk.com/html/2012/07/719368.html

 

Related Article

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.