美文网首页Aide学
Android动画整理小记

Android动画整理小记

作者: 卡路fly | 来源:发表于2020-05-23 15:56 被阅读0次

帧动画

传统方法,通过顺序播放排列好的图片。

补间动画(Tween Animation)

给出两个关键帧,通过一定算法将给定属性值在指定的时间内完成两个关键帧渐变。
只能应用与View对象,主要是操作影像,并不实际变更属性值。

  • 包括四种动画:AlphaAnimation、ScaleAnimation、TranslateAnimation、RotateAnimation
  • 通过AnimationSet,可将动画以组合的形式显示
  • 提供监听方法,可以获取到动画开始、结束、重复事件

属性动画

作用对象较补间动画做了扩展,效果也得到了加强。

1. ObjectAnimation

ObjectAnimator animator = ObjectAnimator.ofFloat(rootView, "translationX", 300);
animator.setDuration(100);
animator.start();

2. PorpertyValuesHolder

类似AnimationSet,可以同时使用多种动画

3. ValueAnimation

属性动画的核心,ObjectAnimation 继承自 ValueAnimation
本身不提供动画效果

4. AnimationSet

  • AnimationSet可以实现更为精确的顺序控制。
  • 通过playTogether(), playSequentially(), animSet.play.with() ,before(), afer() 方法来控制多个动画的协同工作。

布局动画

  • 作用在ViewGroup上,为其添加view时增加动画过度效果
    android:androidLayoutChanges="true"
    Android默认过度效果,无法进行自定义动画替换这个效果
    
  • 使用 LayoutAnimationController 自定义子View 过度
    // 设置过度动画
        ScaleAnimation sa = new ScaleAnimation(0, 1, 0, 1);
        sa.setDuration(2000);
    
        // 设置布局动画显示属性
        LayoutAnimationController controller = new LayoutAnimationController(sa, 0.5F);
        // 顺序
        controller.setOrder(LayoutAnimationController.ORDER_NORMAL);
        
        // 为ViewGroup设置布局动画
        pullListView.setLayoutAnimation(controller);
    

插值器

android:interpolator   影响动画速度
android:shareInterpolator  表示动画是否和集合共享一个插值器

Activity页面切换

  • overridePendingTransition(int enterAnim, int exitAnim)
  • 必须在startActivity()或finish()之后进行调用

相关文章

网友评论

    本文标题:Android动画整理小记

    本文链接:https://www.haomeiwen.com/subject/aifrohtx.html