Viewpager is used in the Android app primarily as a guide page for the program, welcome page, and other animated effects, which will tell you about the use of Viewpager
In Android3.0 above the API, provides the Viewpager interface, so can use directly, but must be above 3.0 to be able to use normally
---------------------------------------------------------------
Get down to the chase.
1. First create a layout in layouts
2. Creating Java Code
① Control Initialization
Private Viewpager Mviewpager;
Mviewpager= (Viewpager) Findviewbyid (R.id.id_viewpager);
PS: Be sure to import android.support.v4.view.ViewPager;
② create an array to hold the ID of the picture
Private int[] Mimagids=new int[]{r.drawable.guide_image1,r.drawable.guide_image2,r.drawable.guide_image3};
③ Creating a Collection
Private list<imageviw> mimages=new arraylist< ImageView > ():
---------------------------initialization & Definition End---------------------
④ Adding an Viewpager adapter
and add two methods:
Public Object Instantiateitem (viewgroup container, int position);
public void Destroyitem (ViewGroup container, int position, object object)
The first method:
Public Object Instantiateitem (viewgroup container, int position) {
ImageView imageview=new ImageView (mainactivity.this);
Imageview.setimageresource (Mimagids[position]);
Imageview.setscaletype (Scaletype.center_crop); Transform
Container.addview (ImageView);//The type of container added is a picture
Mimages.add (IMAGEVIEW[S1]);//Add a picture to the collection
return imageView; }
A second method:
public void Destroyitem (ViewGroup container, int position, object object) {
Container.removeview (Mimages.get (POSITION[S2));
}
A third method:
public Boolean isviewfromobject (view view, Object arg1) {
return VIEW==ARG1;
}
Fourth method:
public int GetCount () {
return mimagids.length;
}
Ps: Adding animations for transforms
Where depthpagetransformer this class is available on Google's website
(http://developer.android.com/training/animation/screen-slide.html)
(due to domestic restrictions on Google: Virtual VPN is recommended (recommended: Xroute))
= = = Because there are errors in copying the classes that Google offers to transform animations, it needs to be perfected
1. Import the Viewpager Package
2.
[S1] Before you create an object for ImageView, and then add the previously created object to the collection
[S2] Every time this picture is crossed, the picture is removed (removed by its position)
The use of Android growth diary-viewpager