Android屬性動畫之ValueAnimation

來源:互聯網
上載者:User

標籤:

  ValueAnimation是ObjectAnimation類的父類,經過前幾天的介紹,相信大家對ObjectAnimation有了 一定的認識,今天就為大家最後介紹一下ValueAnimation,ValueAnimationGoogle提供了更好的過程式控制制,現在就以一個類計時的小動畫為大家簡單介紹一下:

  應用的布局檔案非常簡單,只有一個Button按鈕,就不再贅述了。下面重點介紹一下具體的實現:

public void init() {        button = (Button) findViewById(R.id.fourbutton);        button.setOnClickListener(new myButtonListener());    }    public class myButtonListener implements View.OnClickListener{        @Override        public void onClick(View view) {            final ValueAnimator animator = ValueAnimator.ofInt(1, 100);            animator.setDuration(5000);            animator.setInterpolator(new LinearInterpolator());//線性效果變化            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {                @Override                public void onAnimationUpdate(ValueAnimator valueAnimator) {                    Integer integer = (Integer) animator.getAnimatedValue();                    button.setText("" + integer);                }            });            animator.start();        }    }

  以上就是小應用的全部代碼了,重點在於addUpdateListener()方法的實現,通過重寫ValueAnimator.AnimatorUpdateListener()的onAnimationUpdate(ValueAnimator valueAnimator)方法來對動畫的整個實現過程進行控制。

  到這裡關於Android的屬性動畫實現就介紹完畢了,現在進行一下總結。

1、常用屬性:

  translationX/translationY:水平|豎直位移量

  rotation/rotationX/rotationY:3D翻轉

  scaleX/scaleY:X軸|Y軸的縮放

  X/Y:具體移動到的點

  alpha:透明度

  屬性動畫的這五個屬性,類似於以前的value動畫的四個屬性,不過屬性動畫架構的執行效率更高,效果更好。

2、常用方法和類:

  ValueAnimation、ObjectAnimation類:對於這兩個類,相信大家一定不陌生了,更多的功能請查詢GoogleAPI

  AnimationUpdateListener、AnimationListenerAdapter:用於做屬性動畫的監聽事件

  PopertyValuesHolder:控制動畫集合的顯示效果、順序與流程式控制制

  AnimationSet、TypeEvaluators:值計算機和差值計算機

  Interpolator:動畫顯示的變化規律

3、Interpolator的屬性:

  AccelerateInterpolator:不斷加速

  DecelerateInterpolator:不斷減速

  AnticipateInterpolator:前凸

 

  OvershootInterpolator:尾翹

  LinearInterpolator:線性變化

  BounceInterpolator:自由落體

  以上就是Interpolator差值器的6個屬性,大家可以在項目中都實驗一下,這樣可以更好的理解和使用。

  到今天Android屬性動畫的總結就為大家奉獻完畢,歡迎交流學習([email protected])。

Android屬性動畫之ValueAnimation

聯繫我們

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