Android 開源動畫架構:NineOldAndroids

來源:互聯網
上載者:User

標籤:android   http   color   io   使用   ar   java   for   strong   

介紹

Android 平台提供兩種動畫系統:Property Animation(Android 3.0引入)和View Animation。這兩種動畫都可供選擇,但是Property Animation是首選,因為它更靈活並且提供更強大的功能。除此之外,你還可以使用Drawable Animation,它允許你載入一系列圖片資源並且按照指定的順序一幀一幀的播放。
Property Animation
Introduced in Android 3.0 (API level 11), the property animation system lets you animate properties of any object, including ones that are not rendered to the screen. The system is extensible and lets you animate properties of custom types as well.
譯文:在Android 3.0( API 11)被引入,Property Animation讓你可以讓任何對象做動畫,包括那些沒有被渲染到螢幕上的對象。Property Animation 是可擴充的,同時支援對象的自訂屬性類型動畫。
View Animation
View Animation is the older system and can only be used for Views. It is relatively easy to setup and offers enough capabilities to meet many application‘s needs.
譯文:View Animation 是舊的動畫系統並且只能使用在View對象上。它使用比較簡單,同時提供足夠的動畫功能來滿足許多應用的需要。
Drawable Animation
Drawable animation involves displaying Drawable resources one after another, like a roll of film. This method of animation is useful if you want to animate things that are easier to represent with Drawable resources, such as a progression of bitmaps.

Drawable animation 一張接一張的去顯示一系列圖片資源,像一卷電影菲林。

 

Android property animation 只有在Android 3.0(API 11)以上版本可用,不過好在已經有開源大神幫我們解決這個問題了。這個項目就是NineOldAndroids

NineOldAndroids將Honeycomb animation API 移植到了整個Android Version平台,使得ValueAnimator、ObjectAnimator等Honeycomb animation API 能不改一行代碼,只修改import的包名就完全相容到新的api。

 

Usage

如果你熟悉Honeycomb animation API 的話,那麼使用就非常簡單了,只需要將import android.animation.ObjectAnimator替換為 com.nineoldandroids.animation.ObjectAnimator 即可。

 

?
123456 ValueAnimator colorAnim = ObjectAnimator.ofInt(this"backgroundColor"/*Red*/0xFFFF8080, /*Blue*/0xFF8080FF); colorAnim.setDuration(3000); colorAnim.setEvaluator(new ArgbEvaluator()); colorAnim.setRepeatCount(ValueAnimator.INFINITE); colorAnim.setRepeatMode(ValueAnimator.REVERSE); colorAnim.start();

 

NineOldAndroids 庫幾乎完全相容最新的Android 3.0 Property Animation API

 

 ?
123456789101112 AnimatorSet set = new AnimatorSet(); set.playTogether(     ObjectAnimator.ofFloat(myView, "rotationX"0360),     ObjectAnimator.ofFloat(myView, "rotationY"0180),     ObjectAnimator.ofFloat(myView, "rotation"0, -90),     ObjectAnimator.ofFloat(myView, "translationX"090),     ObjectAnimator.ofFloat(myView, "translationY"090),     ObjectAnimator.ofFloat(myView, "scaleX"11.5f),     ObjectAnimator.ofFloat(myView, "scaleY"10.5f),     ObjectAnimator.ofFloat(myView, "alpha"10.25f, 1); set.setDuration(5 1000).start();

 

Android 開源動畫架構:NineOldAndroids

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.