zoukankan      html  css  js  c++  java
  • 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。




  • 相关阅读:
    2019/10/9 CSP-S 模拟测
    简单的面向对象
    魔术变量
    函数
    全局变量
    超级全局变量
    for循环
    while循环
    php数组排序
    python打造XslGenerator
  • 原文地址:https://www.cnblogs.com/feijian/p/4700119.html
Copyright © 2011-2022 走看看