目的
区分Animation(补间动画)和Animator(属性动画)的区别,加强对属性动画的学习
相关技术、及其使用
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);
注意:属性动画中,
with 同时执行
after 后面执行
before 前面执行
playTogether 同时执行
playSequence 顺序执行
与补间动画相同的是,同样使用AnimatorSet方法给同一控件添加多个动画
AnimatorSet aSet = new AnimatorSet();
aSet.playTogether(scaleAniX,scaleAniY);
aSet.start();
PS
Animator(属性动画)和Animation(补间动画)的主要区别在于前者是改变所需要动画控件的属性值,而后者就是改变视觉效果,并没有改变控件的属性值。通过这个项目对补间动画和属性动画进一步的区别和加深印象,能够熟练的掌握动画的创建和实现。
网友评论