標籤: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", 0, 360), ObjectAnimator.ofFloat(myView, "rotationY", 0, 180), ObjectAnimator.ofFloat(myView, "rotation", 0, -90), ObjectAnimator.ofFloat(myView, "translationX", 0, 90), ObjectAnimator.ofFloat(myView, "translationY", 0, 90), ObjectAnimator.ofFloat(myView, "scaleX", 1, 1.5f), ObjectAnimator.ofFloat(myView, "scaleY", 1, 0.5f), ObjectAnimator.ofFloat(myView, "alpha", 1, 0.25f, 1) ); set.setDuration(5 * 1000).start();
|
Android 開源動畫架構:NineOldAndroids