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