Android屬性動畫ObjectAnimator的使用1


版權聲明:本文為xing_star原創文章,轉載請注明出處!

本文同步自http://javaexception.com/archives/106

屬性動畫ObjectAnimator的使用

屬性動畫在Android開發的使用場景很多,這篇只是記錄基本的API,用ObjectAnimator這個類實現平移,旋轉,縮放,透明度這幾個效果。屬性動畫里面有兩個關鍵的類,ObjectAnimator,ValueAnimator,這篇只講ObjectAnimator的基本用法。

平移

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左右切換效果。

其他資料參考:

Android 屬性動畫:這是一篇很詳細的 屬性動畫 總結&攻略

代碼下載地址:

點擊原文,獲取源代碼下載地址。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM