版權聲明:本文爲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