Explain in detail the method of creating viewpager component in android app
Now, many apps are a viewpager as soon as they are opened, and then they can slide with their fingers. Each time they slide, they change a picture. There will be a circle at the bottom, saying that now they slide to the chapter ~ usually these pictures are for function introduction or use teaching. My needs are very simple, just as mentioned above. There are two ways. One is to find the existing suite and check a pile of data. Everyone recommended me the viewpagerindicator. I've seen this set before, but it seems that there needs to be a fragment, and the Google play example doesn't seem to be available, so I have to make one myself. For the implementation of viewpager, refer to the program code in Android viewpager:
So you have a viewpager
Let's take a specific look at the usage of viewpager: 1. Create viewpager ① add android.support.v4.view.viewpager to the XML layout
② Load the displayed page card to convert the layout into a view object
(1)
(2)
③ Configure adapters (three types of adapters)
(1) Pageradapter data source: List < View > (2) fragmentpageradapter data source: List < fragment > (3) fragmentstatepageradapter data source: List < fragment > 2. Code example: create four fragments and their layouts. The following is the XML layout of mainactivity:
First pageradapter
The second type is fragmentpageradapter
The third type is fragmentstatepageradapter (this adapter can dynamically destroy fragments)
Getsupportfragmentmanager() is used in mainactivity. This activity must inherit fragmentactivity: