Android屬性動畫ObjectAnimator的使用1

版權聲明:本文爲xing_star原創文章,轉載請註明出處!html

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

屬性動畫ObjectAnimator的使用

屬性動畫在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

發表於 2019-05-27 22:48 xing_star  閱讀(1852)  評論(0) 編輯 收藏            .net

相關文章
相關標籤/搜索