安卓的属性动画分为四种类型:平移,旋转,缩放,渐显
四个动画对应四个不同的方法 但是操作的步骤都是一样的 唯一一个就是 渐显 比较简单点
平移:TranslateAnimation Duration代表的是运行一次的时间 RepeatMode代表的是以什么样的模式展示 参数很多 大家可以试试 ReoeatCont是你要运行多少次
TranslateAnimation translateAnimation = new TranslateAnimation(0,100,0,100);
translateAnimation.setFillEnabled(true);
translateAnimation.setFillBefore(true);
translateAnimation.setFillAfter(true);
translateAnimation.setRepeatCount(1);
translateAnimation.setRepeatMode(Animation.ABSOLUTE);
translateAnimation.setDuration(1000);
旋转:RotateAnimation
RotateAnimation rotateAnimation = new RotateAnimation(0,100,0,100);
rotateAnimation .setFillEnabled(true);
rotateAnimation .setFillBefore(true);
rotateAnimation .setFillAfter(true);
rotateAnimation .setRepeatCount(1);
rotateAnimation .setRepeatMode(Animation.ABSOLUTE);
rotateAnimation .setDuration(1000);
缩放:ScaleAnimation Duration代表的是运行一次的时间 RepeatMode代表的是以什么样的模式展示 参数很多 大家可以试试 ReoeatCont是你要运行多少次
ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 0.5f, 1f, 0.5f);
scaleAnimation.setFillEnabled(true);
scaleAnimation.setFillAfter(true);
scaleAnimation.setFillBefore(true);
scaleAnimation.setRepeatMode(Animation.ABSOLUTE);
scaleAnimation.setRepeatCount(1);
scaleAnimation.setDuration(1000);
渐显:AlphaAnimation 第一个参数是开始的显现的程度 第二个是显现的到那个地步这里的Duration代表的是运行一次的时间 RepeatMode代表的是以什么样的模式展示 参数很多 大家可以试试 ReoeatCont是你要运行多少次
AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f,1f);
alphaAnimation.setDuration(1000);
alphaAnimation.setRepeatMode(Animation.ABSOLUTE);
alphaAnimation.setRepeatCount(1);
当然 我们也有一个组合的动画:这个就是把你想要的动画添加在一起 最后的效果当然也是一起展示 其他参数的含义跟其他动画都是一样的
AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(alphaAnimation);
animationSet.addAnimation(translateAnimation);
animationSet.setDuration(1000);
animationSet.setRepeatMode(Animation.ABSOLUTE);
animationSet.setRepeatCount(1);
最后 动画也有一个监听 结束 或者是开始什么的:
translateAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
ARouter.getInstance().build(Arout.Frese).navigation();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});