1. functions implemented by ViewPager and running instructions
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
2. How to Use the ViewPager Control
2.1 reference the ViewPager Control
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.2 configuration 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.3 set the adapter of the ViewPager Control
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)
3. initialize the ViewPager control.
Initialize the adapter of the ViewPager Control
ViewPager1 = (ViewPager) findViewById (R. id. viewPager1 );
ViewPager1.setAdapter (new ImgPagerAdapter (this, lists ));
Configure page change events for the adapter
ViewPager1
. SetOnPageChangeListener (new OnPageChangeListener (){
// Select on the page
@ Override
Public void onPageSelected (int position ){
TopText. setText (String. valueOf (position + 1) + "/" + String. valueOf (lists. length ));
}
@ Override
Public void onPageScrollStateChanged (int state ){
}
@ Override
Public void onPageScrolled (int position,
Float positionOffset, int positionOffsetPixels ){
}
});