Android 學習之補間(Tween)動畫

來源:互聯網
上載者:User

標籤:補間tween動畫四種分類簡單學習

補間動畫,就是開發人員只需要指定動畫的開始,動畫的結束的“主要畫面格”,而動畫變化的“中間幀”由系統計算,並且補齊。這就是補間動畫。

補間動畫共分為四類:

AlphaAnimation(透明動畫),ScaleAnimation(縮放動畫),TranslateAnimation(位移動畫),RoateAnimation(旋轉動畫)

我們依次學習。


a:透明動畫

   public void AlphaAnimation(View v)    {    //0:代表的是全透明,1代表的是全不透明    aa = new AlphaAnimation(0, 1);    //期間2s    aa.setDuration(2000);    //開始播放動畫    iView.startAnimation(aa);    }

透明動畫只需要設定開始的透明度,和結束的透明度,以及設定的動畫延遲時間就行。

b:縮放動畫

public void ScaleAnimation(View v)    {    /* 1:代表x座標的初始值 = 1*iView的寬     * 3:代表x座標的縮放位置 = 3*iView的寬     * 預設的縮放原點是左上方     * */    //sa = new ScaleAnimation(1, 3, 1, 3);        //iView.getWidth()/2, iView.getHeight()/2: 可以修改縮放的原點,是以ImageView的中心作為縮放點    //sa = new ScaleAnimation(0, 3, 0, 3, iView.getWidth()/2, iView.getHeight()/2);            //Animation.RELATIVE_TO_SELF, 1:代表縮放點的x座標 = iView的真實x+1*iView的寬度    //Animation.RELATIVE_TO_SELF, 1:代表縮放點的y座標  = iView的真實y+1*iView的高度    sa = new ScaleAnimation(0, 2, 0, 2, Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 1);        //設定延遲時間    sa.setDuration(2000);        iView.startAnimation(sa);    }

縮放動畫有3個重構方法,每個方法的參數都是不一樣的,建立大家試著設定幾個值試試,就明白其中的含義了。

c:位移動畫

    public void TranslateAnimation(View  v)    {    //0:表示x座標的開始位置 = iView的真實x + 0    //ta = new TranslateAnimation(0, 100, 0, 100);        //Animation.RELATIVE_TO_SELF, 1:表示x的開始座標 = iView的真實x + iv寬*1    ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 1,      Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 1);    ta.setDuration(2000);        iView.startAnimation(ta);            }

位移動畫有兩種構造方法,具體還需自己嘗試嘗試

d:旋轉動畫

    public void  RotateAnimation(View  v)    {    //旋轉開始角度和結束角度    //ra = new RotateAnimation(0, -15);        //ra = new RotateAnimation(20, 360, iView.getWidth()/2, iView.getHeight()/2);        ra = new RotateAnimation(0, 90, Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 1);        ra.setDuration(2000);    iView.startAnimation(ra);    }
總結:補間動畫只需要記住三個重要元素即可, 開始座標,結束座標,以及動畫播放時間就可以了。

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

Android 學習之補間(Tween)動畫

聯繫我們

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