完全參考郭霖大神的資料:
- 上篇: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
講的非常的詳細且易懂个唧,如果大家想學(xué)習推薦大家看下
下面我列舉的只是方便查看而已
ValueAnimator的使用
- ValueAnimator.ofFloat使用:實現(xiàn)的效果是float數(shù)從0-1-0-10的過程
ValueAnimator animatorator = ValueAnimator.ofFloat(0f,1f,0f,10f);
animatorator.setDuration(3000);
animatorator.start();
- ValueAnimator.ofInt使用:實現(xiàn)的效果是整數(shù)從0-100的過程
ValueAnimator animatorator = ValueAnimator.ofInt(0,100);
animatorator.setDuration(3000);
animatorator.start();
- ValueAnimator.ofObject使用:實現(xiàn)一個自定義的數(shù)值淳蔼,以自定義的方法實現(xiàn)變化的過程,其中自定義的方法在TypeEvaluator中窃诉,自定義數(shù)值為Point豆胸,onAnimationUpdate通過來獲取中間變化的數(shù)
//需要自己根據(jù)實際情況編寫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(); //轉(zhuǎn)換成自定義的數(shù)值
invalidate();
}
});
anim.setDuration(5000);
anim.start();
PS: 可以通過設(shè)置anim.setInterpolator(new AccelerateInterpolator(2f)); 來實現(xiàn)官方的一些效果
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轉(zhuǎn)一圈
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: 監(jiān)聽器可查看上面的中篇
***
## ViewPropertyAnimator的使用
- 通過控件調(diào)用animate()來實現(xiàn)動畫效果
textview.animate().x(500).y(500).setDuration(5000)
.setInterpolator(new BounceInterpolator());