Animations 是一套实现动画的 API
Animations 的分类
1、 Tweened Animations 渐变动画、补间动画
提供了旋转、移动、伸展和淡出等效果
2、 Frame-by-Frame Animations
可以创建一个 Drawable 序列,这些 Drawable 可以按照指定的时间间歇一个一个的显
示。
Tweened Animations 的分类
1、 Alpha:淡入淡出效果
2、 Scale:缩放效果
3、 Rotate:旋转效果
4、 Translate:移动效果
Animations 的第一种使用方法:
使用 Tweened Animations 的步骤
1、 创建一个 AnimationSet 对象
2、 根据需要创建相应的 Animation 对象
3、 根据软件动画的需求,为 Animation 对象设置相应的数据
4、 将 Animation 对象添加到 AnimationSet 对象当中
5、 使用控件对象开始执行 AnimationSet
Animation 的四个子类:
AlphaAnimation、TranslateAnimation、ScaleAnimation、RotateAnimation
private class RotateButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
//创建一个AnimationSet对象
AnimationSet animationSet = new AnimationSet(true);
//创建一个RotateAnimation对象
RotateAnimation rotateAnimation = new RotateAnimation(0,
360,
Animation.RELATIVE_TO_PARENT, 0.5f,
Animation.RELATIVE_TO_PARENT, 0.2f);////旋转点的x坐标
为0.5倍父控件的宽度,y坐标为0.2倍父控件的长度
//设置动画执行的时间(单位:毫秒)
rotateAnimation.setDuration(5000);
//将RotateAnimation对象添加到AnimationSet当中
animationSet.addAnimation(rotateAnimation);
//开始动画