您的位置:首页 > 移动开发 > Android开发

android 后台代码设置动画

2015-08-03 18:31 351 查看
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文件中定义Interpolatorandroid:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true"这样所有的Animation共用一个Interpolator。在代码中用代码设置如下anim.setInterpolator(new AccelerateInterpolator());在new一个AnimationSet中传入true则所有的Animation共用Interpolator。

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: