一下几扁博客对android 动画的机制有很详细的解读
http://blog.csdn.net/yanbober/article/details/46481171
http://blog.csdn.net/guolin_blog/article/details/43536355
http://blog.csdn.net/harvic880925/article/details/50752838
视图动画在包android.view.animation下
View Animation(试图动画)可以为所有View设置动画
第一步: 使用静态方法 static Animation android.view.animation.AnimationUtils.loadAnimation(Context context, int id) 第一个参数context,第二个是资源id,返回一个Animation 第二步
调用View组件中的 void startAnimation(Animation animation); 来添加动画,
ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage); Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump); spaceshipImage.startAnimation(hyperspaceJumpAnimation);Node: 特别特别注意:补间动画执行之后并未改变View的真实布局属性值。切记这一点,譬如我们在Activity中有一个Button在屏幕上方,我们设置了平移动画移动到屏幕下方然后保持动画最后执行状态呆在屏幕下方,这时如果点击屏幕下方动画执行之后的Button是没有任何反应的,而点击原来屏幕上方没有Button的地方却响应的是点击Button的事件。
插值可以使用改变动画的速率等
可以看见上面所有的Interpolator都实现了Interpolator接口,而Interpolator接口又继承自TimeInterpolator,TimeInterpolator接口定义了一个float getInterpolation(float input);方法,这个方法是由系统调用的,其中的参数input代表动画的时间,在0和1之间,也就是开始和结束之间。
如下就是一个动画始末速率较慢、中间加速的AccelerateDecelerateInterpolator插值器:
public class AccelerateDecelerateInterpolator extends BaseInterpolator implements NativeInterpolatorFactory { ...... public float getInterpolation(float input) { return (float)(Math.cos((input + 1) * Math.PI) / 2.0f) + 0.5f; } ...... }包文件: android.animation
所有property animation的父类 public abstract class Animator extends Object implements Cloneable
类中有两个内部接口
interface Animator.AnimatorListener、 监听cancel ,end,repeat,start
interface Animator.AnimatorPauseListener 监听paused or resumed
AnimatorListenerAdapter 上面两个接口的实现类,可以覆盖其中特定的函数,来简化工作量。
public class ValueAnimator extends Animator
使用静态方法ofxxx函数为为动画传入属性值(此属性值会按要求插值),返回animation对象设置相关的属性,如动画时间(必须),interpolation,evaluator,动画模式之类的(interpolation官方实现了一些在android.view.animation,evaluator官方实现了一些在android.animation下)调用 animation对象的start()方法。启动动画为ValueAnimator添加ValueAnimator.AnimatorUpdateListener监听在实现ValueAnimator.AnimatorUpdateListener接口的类中完成具体状态更新interface ValueAnimator.AnimatorUpdateListener
abstract void onAnimationUpdate(ValueAnimator animation)方法中的animation就是我们我们调用start方法的对象。我们可以调用animation的getAnimatedValue方法来获得evaluator处理的值。然后我们就可以把这个值应用到你想要的地方了
public final class ObjectAnimator extends ValueAnimator
使用静态ofxxx函数为为动画传入属性值,返回animation对象(参数必须有应用次动画的对象,对象拥有的属性名的字符串形式和任意数量的被插值数据)设置相关的属性,如动画时间(必须),interpolation,evaluator,动画模式之类的调用 animation对象的start()方法。启动动画Node:
ObjectAnimator的ofxxx函数需要传入应用动画的对象的属性名的字符串形式,而ObjectAnimator会自动根据反射机制找到相应的get和set函数(驼峰命名发)。从而调用相应的get和set函数来设置动画的响应属性值。可以注意到ObjectAnimator动画很巧妙地封装了getAnimatedValue得具体实现public final class AnimatorSet extends Animator
AnimatorSet和Animator的关系就像ViewGroup和View的关系一样。前者是后者的容器,但是后者又是前者的父类
我们可以调用AnimatorSet对象的play方法为对象添加一个Animator对象,之后会返回一个AnimatorSet.Builder对象
AnimatorSet.Builder 此类中有一下方法 - after(Animator anim) 将现有动画插入到传入的动画之后执行 - after(long delay) 将现有动画延迟指定毫秒后执行 - before(Animator anim) 将现有动画插入到传入的动画之前执行 - with(Animator anim) 将现有动画和传入的动画同时执行
这些方法都进行了连缀的设计
ObjectAnimator moveIn = ObjectAnimator.ofFloat(textview, "translationX", -500f, 0f); ObjectAnimator rotate = ObjectAnimator.ofFloat(textview, "rotation", 0f, 360f); ObjectAnimator fadeInOut = ObjectAnimator.ofFloat(textview, "alpha", 1f, 0f, 1f); AnimatorSet animSet = new AnimatorSet(); animSet.play(rotate).with(fadeInOut).after(moveIn); animSet.setDuration(5000); animSet.start();包android.animation
public class PropertyValuesHolder extends Object implements Cloneable
http://blog.csdn.net/harvic880925/article/details/50752838
property animation 可以用在非view上面,但是有时我们只需要在view中使用动画,这时候我们就可以使用android 3.1引用如的android.view包下面的ViewPropertyAnimator类了
public class ViewPropertyAnimator extends Object
对view对象使用animate方法获得ViewPropertyAnimator对象。对ViewPropertyAnimator对象设置属性(比如view组件的alpah, scale,动画的时间,interlator )在你想要启动动画的时候调用ViewPropertyAnimator对象的start方法