android 后台代码设置动画

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。




 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值