I. Overview
Android Several animation types are available: View Animation , drawable Animation , Property Animation .
viewanimation quite simple, but only support simple zoom, pan, rotate, transparency basic animation, and have certain limitations.
drawable Animation is the so-called frame animation, generally as drawable background use.
propertyanimation produce the reason that you want View There is a color switch animation; you want to be able to use 3D you want to be animated when the animation stops . View Position is the current position; View Animation Can not be done.
Ii. Methods of Use
(1 ) view Animation (animation of a component)
A. takes the definition xml animation, which can be used in a set The resource defines a variety of effects, use this method to pay attention to the use of the coordinates inside, is the current component of the left edge as the origin. You can use the x%p This defines the relationship to the parent layout. Use animationutils.loadanimation (context, ID) when loading in code; method to get animated and use the component's huojianimageview.setanimation (); method to animate the that can be used when the animation is started. animation Start, or you can use the component's start method.
B. Adopt Java code generation animations, translateanimation , alphaanimation . Create an animation after the Setup method as before.
(2)drawable Animation(continuous change of animation)
define animation-list in drawable and then as a component background, in Java the code gets
Animationdrawable animationdrawable = (animationdrawable) bullimageview.getbackground ();
then start animationdrawable.start ()
The general use of this method requires that the component disappears when the last frame of the animation is controlled to finish playing.
A ImageView code can be customized as follows:
Package Com.animal.bull;import Java.lang.reflect.field;import Android.content.context;import Android.graphics.canvas;import Android.graphics.drawable.animationdrawable;import Android.util.AttributeSet; Import Android.view.view;import Android.widget.imageview;public class MyImage extends ImageView {animationdrawable Animationdrawable;int Totalframe; Field field;public void setanimationdrawable (animationdrawable animationdrawable) {this.animationdrawable = Animationdrawable;totalframe = Animationdrawable.getnumberofframes ();} Public MyImage (context context, AttributeSet Attrs) {Super (context, attrs);//TODO auto-generated constructor stub}@ overrideprotected void OnDraw (canvas canvas) {//TODO auto-generated method Stubtry {if (animationdrawable! = null) {field = AnimationDrawable.class.getDeclaredField ("Mcurframe"); Field.setaccessible (true); int r = Field.getint ( animationdrawable); if (r = = totalFrame-1) {setvisibility (view.invisible);}}} catch (Exception e) {//TODO auto-generated catch blOcke.printstacktrace ();} Super.ondraw (canvas);}}
"Android Advanced" Android all kinds of animation how to use the detailed