android 3.0以後添加的一些動畫 animator 中的 ObjectAnimator: java
1.alpha 透明度
android
//第一個參數爲 view對象,第二個參數爲 動畫改變的類型,第三,第四個參數依次是開始透明度和結束透明度。 ObjectAnimator alpha = ObjectAnimator.ofFloat(text, "alpha", 0f, 1f); alpha.setDuration(2000);//設置動畫時間 alpha.setInterpolator(new DecelerateInterpolator());//設置動畫插入器,減速 alpha.setRepeatCount(-1);//設置動畫重複次數,這裏-1表明無限 alpha.setRepeatMode(Animation.REVERSE);//設置動畫循環模式。 alpha.start();//啓動動畫。
2.scale 動畫
AnimatorSet animatorSet = new AnimatorSet();//組合動畫 ObjectAnimator scaleX = ObjectAnimator.ofFloat(text, "scaleX", 1f, 0f); ObjectAnimator scaleY = ObjectAnimator.ofFloat(text, "scaleY", 1f, 0f); animatorSet.setDuration(2000); animatorSet.setInterpolator(new DecelerateInterpolator()); animatorSet.play(scaleX).with(scaleY);//兩個動畫同時開始 animatorSet.start();
3.translate lua
ObjectAnimator translationUp = ObjectAnimator.ofFloat(button, "Y",button.getY(), 0); translationUp.setInterpolator(new DecelerateInterpolator()); translationUp.setDuration(1500); translationUp.start();
4. rotate spa
AnimatorSet set = new AnimatorSet() ; ObjectAnimator anim = ObjectAnimator .ofFloat(phone, "rotationX", 0f, 180f); anim.setDuration(2000); ObjectAnimator anim2 = ObjectAnimator .ofFloat(phone, "rotationX", 180f, 0f); anim2.setDuration(2000); ObjectAnimator anim3 = ObjectAnimator .ofFloat(phone, "rotationY", 0f, 180f); anim3.setDuration(2000); ObjectAnimator anim4 = ObjectAnimator .ofFloat(phone, "rotationY", 180f, 0f); anim4.setDuration(2000); set.play(anim).before(anim2); //先執行anim動畫以後在執行anim2 set.play(anim3).before(anim4) ; set.start();
5.android 改變背景顏色的動畫實現以下 .net
ObjectAnimator translationUp = ObjectAnimator.ofInt(button, "backgroundColor", Color.RED, Color.BLUE, Color.GRAY, Color.GREEN); translationUp.setInterpolator(new DecelerateInterpolator()); translationUp.setDuration(1500); translationUp.setRepeatCount(-1); translationUp.setRepeatMode(Animation.REVERSE); /* * ArgbEvaluator:這種評估者能夠用來執行類型之間的插值整數值表明ARGB顏色。 * FloatEvaluator:這種評估者能夠用來執行浮點值之間的插值。 * IntEvaluator:這種評估者能夠用來執行類型int值之間的插值。 * RectEvaluator:這種評估者能夠用來執行類型之間的插值矩形值。 * * 因爲本例是改變View的backgroundColor屬性的背景顏色因此此處使用ArgbEvaluator */ translationUp.setEvaluator(new ArgbEvaluator()); translationUp.start();
關於Animation更詳細的教程: code
Android屬性動畫Property Animation系列一之ValueAnimator: 對象
http://blog.csdn.net/feiduclear_up/article/details/45893619 blog
Android屬性動畫Property Animation系列二之ObjectAnimator 教程