Android中屬性動畫的基本用法

在開發中屬性動畫是很經常使用的功能,下面我把屬性動畫的基本用法記錄一下,供他人學習,也逐漸積累本身的知識。java

單個動畫效果:安全

//建立動畫對象,後面的參數依次爲:動畫效果的目標組件,須要改變的該組建的屬性(必須有對應的get和set方法就能夠),後面三個參數寫變化過程對應數值。
ObjectAnimator animator= ObjectAnimator.ofFloat(textView, "TextSize", 15, 50, 15);
//動畫過程所用時間,會按這個世界自動平滑執行
animator.setDuration(6000);
//動畫開始
animator.start();

 

組合動畫效果:ide

//after(Animator anim)   將現有動畫插入到傳入的動畫以後執行
//after(long delay)   將現有動畫延遲指定毫秒後執行
//before(Animator anim)   將現有動畫插入到傳入的動畫以前執行
//with(Animator anim)   將現有動畫和傳入的動畫同時執行
//建立動畫對象,後面的參數依次爲:動畫效果的目標組件,須要改變的該組建的屬性(必須有對應的get和set方法就能夠),後面三個參數寫變化過程對應數值。
        ObjectAnimator animator1= ObjectAnimator.ofFloat(textView, "TextSize", 15, 50, 15);
//這裏每次先獲取目標View的角度       
        float init = textView.getRotation();
//旋轉,道理同上
        ObjectAnimator animator2 = ObjectAnimator.ofFloat(textView,"rotation", init,init+180f);
//平移,道理同上 
        ObjectAnimator animator3 = ObjectAnimator.ofFloat(textView,"TranslationX",curTranslationX,-500f,curTranslationX);
//設置動畫組合的類
        AnimatorSet animatorSet=new AnimatorSet();
//設置3個動畫如何組合搭配
        animatorSet.play(animator2).with(animator1).after(animator3);
//動畫過程所用時間,會按這個世界自動平滑執行
        animatorSet.setDuration(6000);
//動畫開始
        animatorSet.start();

 

爲動畫增長監聽:學習

//這裏是爲動畫添加的監聽,具體實現哪一個方法根據需求選擇便可,例如:動畫執行完畢、動畫執行開始、動畫執行取消、動畫執行重複動做等。
animatorSet.addListener(new AnimatorListenerAdapter() {
    //這裏根據須要實現具體的想要執行的內容
    @Override
    public void onAnimationEnd(Animator animation) {
        super.onAnimationEnd(animation);
    }
});

 

以上。另外對APP進行在線全方位的安全性、兼容性測試,我都會用這個:www.ineice.com測試

相關文章
相關標籤/搜索