思路就是:1.选定你参考的高度和宽度
2.设定x,y的动画开始点和终止点
3.按需求设定动画的
setDuration(1000);动画过程为1000,单位毫秒
setFillAfter(true);动画结束是否保留效果
android中提供了4中动画:
AlphaAnimation 透明度动画效果
ScaleAnimation 缩放动画效果
TranslateAnimation 位移动画效果
RotateAnimation 旋转动画效果
本节讲解TranslateAnimation动画,TranslateAnimation比较常用,比如QQ,网易新闻菜单条的动画,就可以用TranslateAnimation实现,
通过TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 来定义动画
参数说明:
代码如下:
float fromXDelta 动画开始的点离当前View X坐标上的差值
float toXDelta 动画结束的点离当前View X坐标上的差值
float fromYDelta 动画开始的点离当前View Y坐标上的差值
float toYDelta 动画开始的点离当前View Y坐标上的差值
常用方法:
代码如下:
animation.setDuration(long durationMillis);//设置动画持续时间
animation.setRepeatCount(int i);//设置重复次数
animation.setRepeatMode(Animation.REVERSE);//设置反方向执行
Xml属性:
代码如下:
android:duration:运行动画的时间
android:repeatCount:定义动画重复的时间