Android Base Control--viewpager implementing a guided page with animations

Source: Internet
Author: User

Well, it's time for us to learn the basics of control, in fact, the Guide page is very simple, that is, five photos

The traditional Viewpager implementation of the Guide page and the ListView is the same reason, just to change the ListView item into a picture, the Baseadapter replaced Pageradapter, we first look at the traditional guide page

Since the use of Viewpager, then the XML file must have Viewpager, careful you, you may find the last page and a button appears, yes, the XML file must have a button

Beginning also said, Viewpager in fact and the ListView, need a adapter, then from adapter start. Google offers a adapter--pageradapter that is designed to fit Viewpager

Basic Viewpager adapter are so written, is to add a list of the Viewpager to the view and delete the list of the view, it can be said that each Viewpager template

We find the corresponding Viewpager, and then set the adapter, the code initviews, Initlistener, InitData is executed sequentially, this code is not difficult, it is easy to read

Careful you may also find that the boot page is not in the status bar, so we need to set its theme for the status bar transparent

Special Note: It is important to note that the size of the picture problem, if the picture HD is too large, there may be a memory overflow error.

The animated Guide page writing procedure is identical to the tradition, except to set an animation for Viewpager. Google provides Viewpager.setpagetransformer (Boolean reversedrawingorder, Pagetransformer transformer) method to set the transition effect of the boot page, Let's look at the toggle demo provided by Google

From the above effect, just add an animation between the boot page, and Google provides the pagetransformer can be the current location of the guide page operation, such as: Set the change of transparency, set the zoom changes, you can achieve the animation effect of switching

From the above code, you can know when the Viewpager sliding, Su Yue will trigger Transformpage this method, and will be the current position and view pass, here is our view of the operation

①position

    1. Position < 1 (ie-infinity to-1): Let the boot page disappear with a transparency of 0
    2. Position <=0 (i.e.-1 to 0): Let the boot page appear
    3. Position <=1 (i.e. 0 to 1): Let the Guide page animate according to position
    4. Remaining else (1 to infinity): Let the boot page disappear with a transparency of 0

② schematic position

Forgive me for drawing not good-looking, not vivid, if you do not understand the words can be printed on their own log information, the view and position are printed out to help understand

Using Pagetransformer is very simple, as long as the Viewpager settings can be

Google also gives us another animated effect to see

The implementation steps are actually the same as the above steps, specifically we look at Pagetransformer's writing

The principle here is not analyzed, and the above is the same, but the operation is different. In addition to the demo provided by Google, we can imitate Google's demo, write our own animation effect

Effect

Well, today the basic control is here, if you do not understand the words can be practiced, and then use paper and pen thinking, you will have a harvest. I also learn other people's blogs through blogs, and then write out the content of the study through my own way. We'll refuel together, and then the men

Android Base Control--viewpager implementing a guided page with animations

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.