android 视图动画工具类

自己封装的用代码实现android视图动画工具类,拿走不谢!!!

package com.cnki.roundcake;

import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;

/**
 * 视图动画管理类
 * Created by liweidong on 2019/12/4.
 */

public class AnimationManager {

    /**
     * 设置缩放动画
     * @param fromX
     * @param fromY
     * @param toX
     * @param toY
     * @param xType RELATIVE_TO_SELF:相对于自身百分比     RELATIVE_TO_PARENT:当前控件的左上角为起点,+ xvalue * 父控件宽度,为缩放中心 ABSOLUTE:当前控件左上角为起点,+ xvalue 为缩放中心
     * @param xValue
     * @param yType 与xtype同理
     * @param yValue
     * @param durtime
     * @param fillAfter 是否保持结束时位置
     * @param repeatCount -1无限循环
     * @param repeatMode
     * @return
     */
    public static ScaleAnimation getScaleAnimation(float fromX, float toX, float fromY, float toY, int xType, float xValue, int yType, float yValue
        , long durtime, boolean fillAfter, int repeatCount, int repeatMode){
        ScaleAnimation scaleAnimation = new ScaleAnimation(fromX, toX, fromY, toY, xType, xValue, yType, yValue);
        scaleAnimation.setDuration(durtime);
        scaleAnimation.setFillAfter(fillAfter);
        scaleAnimation.setRepeatCount(repeatCount);
        scaleAnimation.setRepeatMode(repeatMode);
        return scaleAnimation;
    }

    /**
     * 设置旋转动画
     * @param fromDegrees
     * @param toDegrees
     * @param pivotXType
     * @param pivotXValue
     * @param pivotYType
     * @param pivotYValue
     * @param durTime
     * @param isFillAfter
     * @param repeatCount
     * @param repeatMode
     * @return
     */
    public static RotateAnimation getRotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue
        , long durTime,boolean isFillAfter, int repeatCount, int repeatMode){
        RotateAnimation rotateAnimation = new RotateAnimation(fromDegrees, toDegrees, pivotXType, pivotXValue, pivotYType, pivotYValue);
        rotateAnimation.setDuration(durTime);
        rotateAnimation.setFillAfter(isFillAfter);
        rotateAnimation.setRepeatCount(repeatCount);
        rotateAnimation.setRepeatMode(repeatMode);
        return rotateAnimation;
    }

    /**
     * 设置透明度动画
     * @param fromAlpha
     * @param toAlpha
     * @param durTime
     * @param repeatCount
     * @param repeatMode
     * @param isFillAfter
     * @return
     */
    public static AlphaAnimation getAlphaAnimation(float fromAlpha, float toAlpha, long durTime, int repeatCount, int repeatMode, boolean isFillAfter){
        AlphaAnimation alphaAnimation = new AlphaAnimation(fromAlpha, toAlpha);
        alphaAnimation.setDuration(durTime);
        alphaAnimation.setRepeatCount(repeatCount);
        alphaAnimation.setRepeatMode(repeatMode);
        alphaAnimation.setFillAfter(isFillAfter);
        return alphaAnimation;
    }

    /**
     * 设置平移动画
     * @param fromXType
     * @param fromXValue
     * @param toXType
     * @param toXValue
     * @param fromYType
     * @param fromYValue
     * @param toYType
     * @param toYValue
     * @param durTime
     * @param repeatCount
     * @param repeatMode
     * @param isFillAfter
     * @return
     */
    public static TranslateAnimation getTranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue
        , long durTime, int repeatCount, int repeatMode, boolean isFillAfter){
        TranslateAnimation translateAnimation = new TranslateAnimation(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);
        translateAnimation.setDuration(durTime);
        translateAnimation.setFillAfter(isFillAfter);
        translateAnimation.setRepeatCount(repeatCount);
        translateAnimation.setRepeatMode(repeatMode);
        return translateAnimation;
    }

    /**
     * 设置组合动画
     * @param durTime
     * @param isFillAfter
     * @param animations
     * @return
     */
    public static AnimationSet getAnimationSet(long durTime, boolean isFillAfter, Animation... animations){
        AnimationSet animationSet = new AnimationSet(true);
        for (Animation animation : animations){
            animationSet.addAnimation(animation);
        }
        animationSet.setDuration(durTime);
        animationSet.setFillAfter(isFillAfter);
        return animationSet;
    }

}

插值器的使用下一篇讲解!!!

你可能感兴趣的:(动画,android,android,动画,视图动画)