標籤:
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 後台代碼設定動畫