ViewPage Lesson 1
Step 1:
Add the following content to the layout file: Because android. support. v4.view is an extension package, this format is also used when you use a semantic view.
Android: id = "@ + id/vp_viewpage"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
Step 2:
Create four layout files: page01.xml, page02, page03, page04
Step 3:
MainActivity:
Public class MainActivity extends Activity {private ViewPager viewpager; private List
Children; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); viewpager = (ViewPager) findViewById (R. id. vp_viewpage); children = new ArrayList
(); Children. add (LayoutInflater. from (this ). inflate (R. layout. page01, null); children. add (getLayoutInflater (). inflate (R. layout. page02, null); children. add (getLayoutInflater (). inflate (R. layout. page03, null); children. add (getLayoutInflater (). inflate (R. layout. page04, null); viewpager. setAdapter (new InnerPagerAdapter ();} public class InnerPagerAdapter extends PagerAdapter {@ Overridepublic int getCount () {// get the number of child-level la s return children. size (); // returns the number of neutron-level la s in the viewpage container.} @ Overridepublic boolean isViewFromObject (View view, Object object) {// determine whether a View object is the object Currently added to the ViewPager container. return view = object ;} // The following two methods are the non-abstract methods that must be implemented in PageAdapter @ Overridepublic Object instantiateItem (ViewGroup container, int position) {// instantiate the View object that needs to be displayed at the position specified in the ViewPager container. View = children. get (position); container. addView (view); return view ;}@ Overridepublic void destroyItem (ViewGroup container, int position, Object object) {// remove the View Object container at the specified position from ViewPager. removeView (children. get (position ));}}}