完全参考郭霖大神的资料:
- 上篇:http://blog.csdn.net/guolin_blog/article/details/43536355
- 中篇:http://blog.csdn.net/guolin_blog/article/details/43816093
- 下篇:http://blog.csdn.net/guolin_blog/article/details/44171115
讲的非常的详细且易懂,如果大家想学习推荐大家看下
下面我列举的只是方便查看而已
ValueAnimator的使用
- ValueAnimator.ofFloat使用:实现的效果是float数从0-1-0-10的过程
ValueAnimator animatorator = ValueAnimator.ofFloat(0f,1f,0f,10f);
animatorator.setDuration(3000);
animatorator.start();
- ValueAnimator.ofInt使用:实现的效果是整数从0-100的过程
ValueAnimator animatorator = ValueAnimator.ofInt(0,100);
animatorator.setDuration(3000);
animatorator.start();
- ValueAnimator.ofObject使用:实现一个自定义的数值,以自定义的方法实现变化的过程,其中自定义的方法在TypeEvaluator中,自定义数值为Point,onAnimationUpdate通过来获取中间变化的数
//需要自己根据实际情况编写TypeEvaluator,也就是下面程序的new PointEvaluator()
ValueAnimator anim = ValueAnimator.ofObject(new PointEvaluator(), startPoint, endPoint);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
currentPoint = (Point) animation.getAnimatedValue(); //转换成自定义的数值
invalidate();
}
});
anim.setDuration(5000);
anim.start();
PS: 可以通过设置anim.setInterpolator(new AccelerateInterpolator(2f)); 来实现官方的一些效果
ObjectAnimator的使用
-
ObjectAnimator 透明度修改:textView透明度从1-0-1;
ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "alpha", 1f, 0f, 1f); animator.setDuration(5000); animator.start();
-
ObjectAnimator 改变textView的x值;
float curTranslationX = textview.getTranslationX();
ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "translationX", curTranslationX, -500f, curTranslationX);
animator.setDuration(5000);
animator.start();
- **ObjectAnimator** 角度修改:textView转一圈
ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "rotation", 0f, 360f);
animator.setDuration(5000);
animator.start();
- **ObjectAnimator**改变textView的高度;
ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "scaleY", 1f, 3f, 1f);
animator.setDuration(5000);
animator.start();
- **ObjectAnimator**组合动画;
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();
PS: 监听器可查看上面的中篇
***
## ViewPropertyAnimator的使用
- 通过控件调用animate()来实现动画效果
textview.animate().x(500).y(500).setDuration(5000)
.setInterpolator(new BounceInterpolator());
网友评论