Example of multi page sliding switching effect using viewpager in Android Application
1. Add the Android support package because the above classes are only provided in the Android support package. Let's add the package first. In eclipse - > window - > Android SDK manager, select Extras - > Android support library in the list to install. After downloading, select the V4 version in the Android SDK \ extras \ Android \ support directory, enter the V4 directory, and copy the android-support-v4.jar file to the LIBS directory of the project (if not newly created). ADT will automatically import it into the project during compilation.
2. Create a new layout for the viewpager, as follows
Viewpager is used to manage layout and can slide left and right to display each page data. Pagertabstrip is used to display page title and Android: layout_ Gravity = "top" means that the title is at the top, and the bottom can be set.
3. Create a new fragmentactivity page. The fragmentactivity page contains the viewpager element, which can be used to display fragments. The definition is as follows:
Mypageradapter is integrated from ragmentpageradapter and provides data source for viewpager.
The oncreate function obtains the viewpager instance and sets the data source. Getsupportfragmentmanager indicates that the fragment manager is obtained. Viewpagerfragment1 represents a specific page, as described below.
4. Create a new fragment page. The fragment page is the page to be displayed by sliding left and right. Create a new class integration fragment and override the oncreateview function. Oncreateview function is equivalent to oncreate function of activity. As follows:
5. Example engineering Code:
The simple effect is as follows: