The use of Android growth diary-viewpager

Source: Internet
Author: User

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

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.