android 後台代碼設定動畫

來源:互聯網
上載者:User

標籤:

1、設定旋轉動畫

final RotateAnimation animation =new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF,0.5f);

 animation.setInterpolator(new LinearInterpolator());  // LinearInterpolator 表示均勻速率animation.setDuration(3000);//設定動畫期間animation.setRepeatCount(Animation.INFINITE); //表示重複多次,也可以用具體的次數ll_earn_circle_bg.startAnimation(animation);  //ll_earn_circle_bg  是一個LinearLayout控制項

2、設定位移動畫

/**      *  CycleTimes動畫重複的次數     * @param CycleTimes     */    public void shakeAnimation(int CycleTimes) {        if (null == mShakeAnimation) {            mShakeAnimation = new TranslateAnimation(0, 10, 0, 0);            mShakeAnimation.setInterpolator(new CycleInterpolator(CycleTimes));  //設定速度,,CycleInterpolator某種數學上的曲線,即搖晃的速率曲線化            mShakeAnimation.setDuration(1500);            mShakeAnimation.setRepeatMode(Animation.REVERSE);//設定反方向執行         }        tv_curmoney.startAnimation(mShakeAnimation);  //tv_curmoney是一個textview控制項    }

 

3、設定縮放動畫
/** 設定縮放動畫 */         final ScaleAnimation animation =new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);         animation.setDuration(2000);//設定動畫期間         iv_go_rank.startAnimation(animation); // iv_go_rank 是一個imageview控制項

 

關於速率的介紹:

在xml檔案中定義Interpolator

android:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true"

這樣所有的Animation共用一個Interpolator。

在代碼中用代碼設定如下

 

anim.setInterpolator(new AccelerateInterpolator());

在new一個AnimationSet中傳入true則所有的Animation共用Interpolator。




 

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.