android 屬性動畫之 ObjectAnimator,android屬性動畫

來源:互聯網
上載者:User

android 屬性動畫之 ObjectAnimator,android屬性動畫

前面一篇部落格講解了 android 簡單動畫之 animtion,這裡來講解一下android 3.0之後添加的一些動畫   animator 中的 ObjectAnimator 。

1.alpha 

//第一個參數為 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

ObjectAnimator translationUp = ObjectAnimator.ofFloat(button, "Y",button.getY(), 0);translationUp.setInterpolator(new DecelerateInterpolator());translationUp.setDuration(1500);translationUp.start();

4. rotate

   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 改變背景顏色的動畫實現如下

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();







android,在xml中定義objectAnimator動畫的問題

0%就是原位置 你設定成 from -100% to 0 試試
 
android中的動畫有哪幾類,它們的特點與不同是什?

android支援兩種動畫模式,tween animation,frame animation
View Animation(Tween Animation):補間動畫,給出兩個主要畫面格,通過一些演算法將給定屬性值在給定的時間內在兩個主要畫面格間漸層。
  View animation只能應用於View對象,而且只支援一部分屬性,這種實現方式可以使視圖組件移動、放大、縮小以及產生透明度的變化.

另一種Frame動畫,傳統的動畫方法,通過順序的播放排列好的圖片來實現,類似電影。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.