ViewAnimUtil.java 2.54 KB
package com.cnlive.strike.xiaojiaspeaker;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Build;
import android.os.Handler;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.animation.Animation;
import android.view.animation.BounceInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;

import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;

/**
 * 圆形按钮点击特效
 *
 * @author ShinnyYang
 */
public class ViewAnimUtil {

    //设置控件显示放大动画
    public static void setViewShowZoomIn(View view, float zoomIn) {
        try {
            //放大动画
            AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画
            ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1, zoomIn);
            ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1, zoomIn);
            //延时播放缩小动画
            ObjectAnimator scaleXBack = ObjectAnimator.ofFloat(view, "scaleX", zoomIn, 1);
            scaleXBack.setStartDelay(500);
            ObjectAnimator scaleYBack = ObjectAnimator.ofFloat(view, "scaleY", zoomIn, 1);
            scaleYBack.setStartDelay(500);
//            ObjectAnimator rotateBack1 = ObjectAnimator.ofFloat(view, "rotation", 30f, 0f).setDuration(100);
////            //顺时针旋转45°
//            ObjectAnimator rotate = ObjectAnimator.ofFloat(view, "rotation", 30f, 30f).setDuration(100);
//            rotate.setStartDelay(300);
////            //逆时针旋转45°
//            ObjectAnimator rotateBack = ObjectAnimator.ofFloat(view, "rotation", 30f, 0f).setDuration(100);
//            rotateBack.setStartDelay(300);
            //旋转
            ObjectAnimator rotateBack = ObjectAnimator.ofFloat(view, "rotation", 0, 30, -30, 16, -16, 13, -13, 0);
            rotateBack.setStartDelay(100);
            animatorSetsuofang.play(scaleX).with(scaleY).with(scaleXBack).with(scaleYBack).with(rotateBack);//两个动画同时开始
            animatorSetsuofang.setInterpolator(new DecelerateInterpolator());
            animatorSetsuofang.setDuration(500);
            animatorSetsuofang.start();

//            YoYo.with(Techniques.Swing)
//                    .duration(1000)
//                    .repeat(0)
//                    .playOn(view);
        } catch (Exception e) {
        }
    }
}