In fact, animation this thing I have known for a long time, but has not been systematically organized. All kinds of animations in Android are used, but always afraid that they will slowly forget. This time to see a few animated analysis of the article, I also learned some things, in this comb.
Note: All view animations are restricted to its parent control, even if you do a view move, it is not possible to display outside of the parent control. That is, the parent control is a stage where the actor can move around on the stage, but if the stage is exceeded, the audience will not be able to see it.
First, View Animation (Tween Animation)
View Animation (Tween Animation): Also known as motion Tween (Tween Animation), two keyframes are given, and some algorithms are used to ramp the given attribute value between two keyframes in a given time period.
View animation can only be applied to view objects, and only a subset of properties are supported, such as scaling rotation and not supporting background color changes.
For view animation, it simply changes the location of the View object's drawing, noting that this is "drawing" rather than the actual position. For example, you make a button twice times the size of it, but it can accept the area you clicked or the original button area without making any changes.
The View animation supports the setting of various animation styles, as well as the order in which these animations are executed, enabling animation to be animated in both XML and code.
Examples of animations
"By XML"
<?XML version= "1.0" encoding= "Utf-8"?> <Setxmlns:android= "Http://schemas.android.com/apk/res/android"Android:interpolator= "@android: Anim/accelerate_interpolator"Android:shareinterpolator= "true"Android:startoffset= " the"> <Alphaandroid:duration= "$"Android:fromalpha= "1.0"Android:toalpha= "0.0" /></Set>
Animation aimation = animationutils.loadanimation (this, R.anim.anim); Final ImageView ImageView = (ImageView) Findviewbyid (r.id.imageview_id); Imageview.startanimation (aimation);
You can add listeners to an animation
Aimation.setanimationlistener (new Animation.animationlistener () {@Override public void Onanimationstart (Animation Animation) {} @Override public void Onanimationend (Animation Animation) {Animation = null ; } @Override public void Onanimationrepeat (Animation Animation) {}});
If you set the animation with Animationset, Animationset is also inherited from animation, so there are setanimationlistener methods
Detailed code can refer to:http://www.cnblogs.com/tianzhijiexian/p/3983616.html
"By JAVA"
You can refer to this article for the Java code. In fact, a variety of classes inherit animation, and then have their own unique method, can also be animationset through various settings.
Http://www.cnblogs.com/tianzhijiexian/p/3981241.html
Second, drawable Animation (Frame Animation)
Drawable Animation (frame Animation): Frame animation, like a GIF picture, simulates the effect of animation by displaying a series of drawable in turn. The definition in XML is as follows:
<animation-listxmlns:android= "Http://schemas.android.com/apk/res/android"Android:oneshot= "true">
<Itemandroid:drawable= "@drawable/rocket_thrust1"android:duration= "$" /> <Itemandroid:drawable= "@drawable/rocket_thrust2"android:duration= "$" /> <Itemandroid:drawable= "@drawable/rocket_thrust3"android:duration= "$" />
</animation-list>
You must use <animation-list> as the root element, <item> to represent the picture to rotate, and the duration property to indicate when the items are displayed. The XML file should be placed in the/res/drawable/directory.
protected voidonCreate (Bundle savedinstancestate) { Super. OnCreate (Savedinstancestate);
Setcontentview (R.layout.main); ImageView=(ImageView) Findviewbyid (R.ID.IMAGEVIEW1); Imageview.setbackgroundresource (R.drawable.drawable_anim); Animationdrawable Anim=(animationdrawable) imageview.getbackground (); } Public Booleanontouchevent (Motionevent event) {if(event.getaction () = =Motionevent.action_down) {anim.stop (); Anim.start (); return true; } return Super. Ontouchevent (event); }
I encountered two problems in the experiment:
- To call ImageView's Setbackgroundresource method in code, set its Src property directly in the XML layout file when the animation is triggered by FC.
- Stop () before the animation start (), or it will stop at the last frame after the first animation, so the animation will only fire once.
- The last point is mentioned in the SDK, do not call start in OnCreate, because animationdrawable is not fully associated with the window, if you want the interface to start animation, you can be in the onwindowfoucschanged () Call Start () in the
Third, Property Animation
Android Animation Learning Notes