android动画的实现

来源:互联网 发布:mac移除应用程序 编辑:程序博客网 时间:2024/05/17 04:57

android动画的实现

  • 一: 从分类上讲,动画分为帧动画和补间动画。

    • 1.android在3.0以前有四个类来实现补间动画:TranslationAnimation,ScaleAnimation,AlphaAnimation,RotateAnimation
    • 2.实现帧动画的类:在xml中编写animation-list,然后用AnimationDrawable加载,调用start方法开启动画;
    • 3.在android3.0之后谷歌定义的新的方式来实现补间动画:ObjectAnimator,我们通常将其称为属性动画。用法如下:

      ObjectAnimator animator = ObjectAnimator.ofFloat(target, "translationX", values);animator.setDuration(300);animator.start();
    • 4.然而由于ObjectAnimator是3.0之后出来的,早期的时候谷歌并没有兼容的方案,此时,有一位大神Jake Wharton,实现了兼容低版本的属性动画,这个类库就是NineOldAndroid,并且对其进行简化封装,提供的链式api的风格,如下;

      ViewPropertyAnimator.animate(listView)    .translationX(100)    .scaleX(1.2f)    .alpha(0.8f)    .setDuration(500)    .start();
    • 5.直到android4.4之后,谷歌才出了兼容低版本的属性动画,在v4包中ViewCompat类中,用法和ViewPropertyAnimator一模一样;

    • 6.同时还有允许我们进行自定义动画的类在3.0之后出现,就是ValueAnimator;用法如下:

      ValueAnimator valueAnimator = ValueAnimator.ofInt(srcint, decint);//完成srcint到decint的数值渐变
0 0