1、补间动画Animation
Animation
-TranslateAnimation
-AlphaAnimation
-ScaleAnimation
-RotateAnimation
缺点:补间动画只是视觉效果改变,并没有改变控件的属性,所以尽量少用
2、属性动画Animator
Animator
-ValueAnimator 属性的值变了 视觉没变
-ObjectAnimator 属性、视觉都改变了
-TimeAnimator
属性动画是真正的改变了属性的值
例如:
(1)、系统属性alpha 透明度 scalex横向拉伸 scaley纵向拉伸translationx 横向移动 translationy 纵向移动rotation,rotationx rotationy 旋转
(2)、自定义控件属性 这个属性必须实现set get方法
(3)、使用属性动画改变控件透明度
//透明度alpha
public void test1(){
/*
1.target 需要动画的控件
2、propertyName 控件的那个属性
3、...values 变化的值 start - end
*/
ObjectAnimator alphaAni = ObjectAnimator.ofFloat(v,"alpha",1,0);
alphaAni.setDuration(1000);
alphaAni.start();
}
(4)、使用属性动画使控件旋转
//旋转
public void test2(){
ObjectAnimator rotateAni = ObjectAnimator.ofFloat(v,"rotation",0,360);
rotateAni.setDuration(1000);
rotateAni.start();
}
(5)、使用属性动画进行缩放
public void test3(){
ObjectAnimator scaleAniX = ObjectAnimator.ofFloat(v,"scaleX",1,1.1f,1.1f,1);
scaleAniX.setDuration(1000);
scaleAniX.setRepeatCount(-1);
scaleAniX.setRepeatMode(ValueAnimator.RESTART);
ObjectAnimator scaleAniY = ObjectAnimator.ofFloat(v,"scaleY",1,1.1f,1.1f,1);
scaleAniY.setDuration(1000);
scaleAniY.setRepeatCount(-1);
scaleAniY.setRepeatMode(ValueAnimator.RESTART);
}
(6)、注意
属性动画中,
with 同时执行
after 后面执行
before 前面执行
playTogether 同时执行
playSequence 顺序执行
与补间动画相同的是,同样使用AnimatorSet方法给同一控件添加多个动画
AnimatorSet aSet = new AnimatorSet();
aSet.playTogether(scaleAniX,scaleAniY);
aSet.start();