Android学习之Animation

2016-11-08  本文已影响28人  白令海峡

完全参考郭霖大神的资料:

讲的非常的详细且易懂,如果大家想学习推荐大家看下
下面我列举的只是方便查看而已


ValueAnimator的使用

       ValueAnimator animatorator = ValueAnimator.ofFloat(0f,1f,0f,10f);
       animatorator.setDuration(3000);
       animatorator.start();
      
       ValueAnimator animatorator = ValueAnimator.ofInt(0,100);
       animatorator.setDuration(3000);
       animatorator.start();
      //需要自己根据实际情况编写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 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());

上一篇下一篇

猜你喜欢

热点阅读