版权声明:本文为xing_star原创文章,转载请注明出处!html
本文同步自http://javaexception.com/archives/106java
属性动画在Android开发的使用场景不少,这篇只是记录基本的API,用ObjectAnimator这个类实现平移,旋转,缩放,透明度这几个效果。属性动画里面有两个关键的类,ObjectAnimator,ValueAnimator,这篇只讲ObjectAnimator的基本用法。ide
private void translate() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(textView, "translationX", -textView.getLeft(), mWidth, 0); objectAnimator.setDuration(1500); objectAnimator.start(); }
private void rotate() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(textView, "rotation", 0, 360); objectAnimator.setDuration(1500); objectAnimator.start(); }
private void scale() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(textView, "scaleX", 1f, 3f, 1f); ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(textView, "scaleY", 1f, 1.5f, 1f); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(1500); animatorSet.playTogether(objectAnimator, objectAnimator2); animatorSet.start(); }
private void alpha() { ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(textView, "alpha", 1f, 0f, 1f); objectAnimator.setDuration(1500); objectAnimator.start(); }
在http://javaexception.com/archives/64 这篇文章中,就有用到属性动画实现view左右切换效果。post
Android 属性动画:这是一篇很详细的 属性动画 总结&攻略动画
点击原文,获取源代码下载地址。url