关于 ViewPropertyAnimator 笔记

17 阅读1分钟

还记得之前ObjectAnimator怎么创建动画吗,ViewPropertyAnimator创建就非常简单

  1. animate()函数会返回一个ViewPropertyAnimator对象来实现动画属性。
  2. 多个动画方法可以串行调用。
  3. 调用完成直接执行,不需要start方法。
  4. 允许设置AnimatorListener监听器。

完整调用示例:

view.animate().alpha(0.50f).setListener(new Animator.AnimatorListener(){
        public void onAnimationStart(Animator animation) { 
        } 
        public void onAnimationEnd(Animator animation) {
        } 
        public void onAnimationCancel(Animator animation) {
        }
        public void onAnimationRepeat(Animator animation) {
        }

});

相关方法 image.png 取自《Android自定义控件开发入门与实战》

其他: ViewPropertyAnimator不像ObjectAnimaotr 使用反射和JNI技术,理论上性能是更优的但无伤大雅。最大优点在于 如果使用系统属性的动画,不需要自定义属性时,使用很方便。