Android動畫使用

來源:互聯網
上載者:User

標籤:

Android動畫基本上分為兩個時代,一個是3.0(api14)之前的Animation動畫,一個是3.0之後的Animator動畫。

Animation動畫ViewGroup在繪製當前所要播放動畫的view的時候,先回通過ViewGroup的drawChild函數擷取該View的Animation的Transformation值, 然後調用canvas.concat方法,通過矩陣運算和invalidate方法完成動畫,這樣消耗更多的CPU資源。

1. Tween動畫Alpha、Scale、Rotate、Translation
1.代碼 AnimationSet動畫屬性集
2.布局 AnimationUtil

2. Frame動畫圖片輪詢播放

Animator動畫

採用AnimatorSet和ObjectAnimator配合,使用ObjectAnimator進行更精細化控制,並且能夠自動驅動,多個ObjectAnimator組合到AnimatorSet形成一個動畫。減少動畫過程中頻繁繪製,減少CPU的資源消耗.

可操縱的屬性參數:x/y;scaleX/scaleY;rotationX/ rotationY;transitionX/ transitionY;alpha

1.translationX和translationY:控制著View對象從它版面配置容器的左上方座標開始的位置。
2.rotation、rotationX和rotationY:控制View對象圍繞支點進行2D和3D旋轉。
3.scaleX和scaleY:控制著View對象圍繞它的支點進行2D縮放。
4.pivotX和pivotY 控制著View對象的支點位置,預設情況下,該支點的位置就是View對象的中心點。
5.x和y:描述了View對象在它的容器中的最終位置,它是最初的左上方座標和translationX和translationY值的累計和。
6.alpha:它表示View對象的alpha透明度。預設值是1,0代表完全透明。

ValueAnimator---自由落體

final ValueAnimator animator = ValueAnimator.ofFloat(0, screenHeight - imageView.getHeight());animator.setTarget(view);animator.setInterpolator(new BounceInterpolator());animator.setDuration(1000).start();animator.addUpdateListener(new AnimatorUpdateListener() {@Overridepublic void onAnimationUpdate(ValueAnimator animation) {Float value = (Float) animation.getAnimatedValue();imageView.setTranslationY(value);}});

或者:

ObjectAnimator animator = ObjectAnimator.ofFloat(mImageView, "translationY", 100.0f, 0.0f);animator.setInterpolator(new BounceInterpolator());animator.setDuration(1000);animator.start();

ObjectAnimator---透明度和位移

ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "alpha", 0f, 1.0f);animator.setDuration(1000);animator.start();animator.addListener(new AnimatorListenerAdapter() {@Overridepublic void onAnimationEnd(Animator animation) {super.onAnimationEnd(animation);imageView.setTranslationY(400);}});
或者:

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"android:duration="1500"android:propertyName="alpha"android:valueFrom="0.0"android:valueTo="1.0"android:valueType="floatType" ></objectAnimator>Animator animator = AnimatorInflater.loadAnimator(LoginAlphaAnimation.this, R.animator.alpha_login);animator.setTarget(mImageView);animator.start();

AnimatorSet---組合動畫

ObjectAnimator animator1 = ObjectAnimator.ofFloat(imageView, "scaleX", 1f, 2f);ObjectAnimator animator2 = ObjectAnimator.ofFloat(imageView, "scaleY", 1f, 2f);ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageView, "translationY", 0f, 500f);ObjectAnimator animator4 = ObjectAnimator.ofFloat(imageView, "alpha", 1.0f, 0f);AnimatorSet set = new AnimatorSet();set.setDuration(1000);set.playTogether(animator1, animator2, animator3,animator4);set.start();


下載Demo



Android動畫使用

聯繫我們

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