Animations Presentation

Animations Presentation


  • Know how to create an animation and apply it to a View

Animations on Android

  • View animations
    • Originally this was the only method to animate on Android
    • A View can be animated in a limited number of ways by changing how it is drawn
    • Can move, resize, fade and rotate
  • Property animations
    • Introduced in Android 3.0 (API level 11)
    • More general way where any property on a View that can change value in increments can be animated
    • View is actually changed during animation, not just redrawn, meaning other Views in a layout might change too
  • Animations can be defined
    • In XML resource files
    • In Java code

Do a view animation

  • Create and execute a fade-in animation
    AlphaAnimation anim = new AlphaAnimation(0, 1);
  • Limited to the predefined classes
    • TranslationAnimation, ScaleAnimation, RotateAnimation

Do a property animation

  • Create and execute a fade-in animation
    ObjectAnimator anim = ObjectAnimator.ofFloat(view, "alpha", 0, 1);
  • Can animate any property on an object over time
    • Must have set-method, like "setAlpha" when specifying "alpha"
    • Limited by type support, ofInt, ofFloat, ofObject