Viewpager realizes multi page switching effect in Android Development

Viewpager is used to realize the switching effect of multiple pages. This class exists in Google's compatibility package, so remember to add "android-support-v4. Jar" in buildpath when referencing

First of all, you must know that to use viewpager, you must use pageradapter to provide data for it, and you must implement the following four methods:

1. Getcount(): the number of pages to be displayed by viewpager

2. Isviewfromobject (view, object): view is the page of a certain location, and object is returned by the instantiateitem method. In this method, you need to judge whether the page and the object object are the same

No is the same object.

3. Instantiateitem (ViewGroup container, int position): generate a page at the corresponding position. Container is the container for displaying the page, and position is the serial number of the corresponding page

4. Destroy item (ViewGroup container, int position, object): destroy the specified page

The implementation code is as follows:

1. Directly introduce viewpager into the layout file

Note: you must import its dependent package android.support.v4

2. Customize an adapter to inherit from pageradapter and override its four methods

3. Implement its logic in activity

The above is what Xiaobian introduced to you. In Android development, viewpager realizes multi page switching effect. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>