android 视图动画工具类
程序员文章站
2022-03-17 11:18:38
...
自己封装的用代码实现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;
}
}
插值器的使用下一篇讲解!!!
上一篇: jQuery制作拼图小游戏_jquery
下一篇: 国王和100个囚犯
推荐阅读
-
Android手机管理工具类详解
-
Android开发之超强图片工具类BitmapUtil完整实例
-
Android开发实现的Intent跳转工具类实例
-
Android开发中日期工具类DateUtil完整实例
-
Android开发中超好用的正则表达式工具类RegexUtil完整实例
-
Android开发实现查询远程服务器的工具类QueryUtils完整实例
-
Android 数据存储之 FileInputStream 工具类及FileInputStream类的使用
-
Android开发之图形图像与动画(一)Paint和Canvas类学习
-
Android开发之多媒体文件获取工具类实例【音频,视频,图片等】
-
Android开发中的文件操作工具类FileUtil完整实例