在开发中属性动画是很经常使用的功能,下面我把属性动画的基本用法记录一下,供他人学习,也逐渐积累本身的知识。java
单个动画效果:安全
//建立动画对象,后面的参数依次为:动画效果的目标组件,须要改变的该组建的属性(必须有对应的get和set方法就能够),后面三个参数写变化过程对应数值。 ObjectAnimator animator= ObjectAnimator.ofFloat(textView, "TextSize", 15, 50, 15); //动画过程所用时间,会按这个世界自动平滑执行 animator.setDuration(6000); //动画开始 animator.start();
组合动画效果:ide
//after(Animator anim) 将现有动画插入到传入的动画以后执行 //after(long delay) 将现有动画延迟指定毫秒后执行 //before(Animator anim) 将现有动画插入到传入的动画以前执行 //with(Animator anim) 将现有动画和传入的动画同时执行 //建立动画对象,后面的参数依次为:动画效果的目标组件,须要改变的该组建的属性(必须有对应的get和set方法就能够),后面三个参数写变化过程对应数值。 ObjectAnimator animator1= ObjectAnimator.ofFloat(textView, "TextSize", 15, 50, 15); //这里每次先获取目标View的角度 float init = textView.getRotation(); //旋转,道理同上 ObjectAnimator animator2 = ObjectAnimator.ofFloat(textView,"rotation", init,init+180f); //平移,道理同上 ObjectAnimator animator3 = ObjectAnimator.ofFloat(textView,"TranslationX",curTranslationX,-500f,curTranslationX); //设置动画组合的类 AnimatorSet animatorSet=new AnimatorSet(); //设置3个动画如何组合搭配 animatorSet.play(animator2).with(animator1).after(animator3); //动画过程所用时间,会按这个世界自动平滑执行 animatorSet.setDuration(6000); //动画开始 animatorSet.start();
为动画增长监听:学习
//这里是为动画添加的监听,具体实现哪一个方法根据需求选择便可,例如:动画执行完毕、动画执行开始、动画执行取消、动画执行重复动做等。 animatorSet.addListener(new AnimatorListenerAdapter() { //这里根据须要实现具体的想要执行的内容 @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); } });
以上。另外对APP进行在线全方位的安全性、兼容性测试,我都会用这个:www.ineice.com。测试