Android Animation Implementation-Simple

Source: Internet
Author: User

Basic knowledge of Android animation can be consulted: Android animation preliminary, Android animation Tween Animation, Android animation Frame Animation, Android Properties Animation (property Animation) , Android Animation Property Animation, Objectanimator demo above these are the basic knowledge of Android animation, master these basic knowledge, we can come to practice, first to Zhang final.

First GIF

Second GIF

First of all, there are several ways to implement the above animations on Android
1. Simple implementation, directly with GIF, we know that Android does not natively support GIF before 5.0, but it has everything on GitHub, so finding a third-party class library that supports GIF is not difficult.
2. Another simple implementation, directly with the tween Animation, the implementation is relatively simple.
3. The above two methods have a common disadvantage, the app volume will increase a lot, because at least to put the local dynamic map or frame by picture, in addition to poor performance of the mobile phone performance is poor, the user experience is not good, then what better way, of course, Android provides us with a strong enough Animator system, the use of Animator can be very good to achieve the above effect, this blog blogger will follow you together to achieve the above animation effect. Before revealing a bit, all animations using Android 3.0 are introduced after the Animator, if you want to compatible with Android 3.0 can use Nineoldandroids Third party animation library.

Also, if you don't have a basic animation base, read the previous Animated Basics series blog post.

Implementation analysis

To analyze the first GIF diagram first:
This figure a total of 9 animation action, and is the order of execution, this is the basic idea, and then refinement down, wherein the 9 animation action further divided into alpha + scaleX + scaleY and so on superposition action, so must be on the sequence of action, superposition action has a basic understanding, There is also a basic knowledge of the coordinates, such as the last action, pulled from the left side of the animation, the static figure is located in the center position (0,0) as the relative coordinates, the upper left corner of Android (0,0) origin coordinates for the absolute coordinates, so at the beginning of the map coordinates x
The values on the axis are calculated as follows:

new"translationX"220F);

Second GIF picture:
And the previous picture basically almost, the only difference is that the animation superposition action is more, the other basic same, so no longer repeat.
Let's take the first animation, the small house from the bottom of the rebound animation as an example.

Animation implementation
Private void Translatefrombuttom() {Objectanimator objectanimator = objectanimator.offloat (Mhouse,"Translationy", Mhouse.getheight (),0F);//The animation shifts in the y-axis, note the coordinate calculations here, and the previous reference to how coordinates are computed. Objectanimator.setduration ( the);//Set animation timeObjectanimator.setinterpolator (NewBounceinterpolator ());//Set rebound effectObjectanimator.addlistener (NewAnimatorlisteneradapter ()//Set Animation listener{@Override         Public void Onanimationstart(Animator animation) {Super. Onanimationstart (animation); Mhouse.setvisibility (view.visible);//start to hide the small house, the animation will be displayed after the opening. }@Override         Public void Onanimationend(Animator animation) {Super. Onanimationend (animation); Scalealpha ();//Start a second animation}    }); Objectanimator.start ();}

This action is relatively simple, is a single animation along the y-axis direction, the following several animations can be comprehend by analogy, no longer detailed, directly on the dry.



The following several animations are similar, so no longer given, so that the first animation is over, isn't it simple (^o^)/~

Next, we look at the implementation of the second animation, said the second animation in addition to a single animation composite action than more, the other and the first animation is the same, so we go directly to the key point, nonsense less, directly affixed to the second four similar composite animation implementation, the other few are relatively simple, no longer repeat.

Next comes the animated effect from the surrounding

So the second animation is complete, in the specific development, if you do not notice in the activity of the OnCreate (Bundle savedinstancestate) life cycle to achieve some of the above column animation, then almost certainly, the first animation will certainly compare card , this certainly has nothing to do with the performance of the phone, why is this so? As long as you have seen the above-mentioned Android animation base blog, you can certainly find the answer, here no longer repeat, well, the above practice to this end, the following Android animation blog post will involve a complex implementation, please look forward to.

Android Animation Implementation-Simple

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.