Measuring Views • Problem: Views not measured until sometime after inflation • ViewTreeObserver - lets you know when a View has been measured • OnGlobalLayoutListener • OnPreDrawListener • Can cancel drawing before it happens
Measuring "After" • Align to other existing Views • Create invisible "dummy" Views to animate towards • Start in the correct position, animate towards it
Property Animators • Generic animation framework • Animates any value over time • Not limited to just visual animations • Basic building block for most animations
ObjectAnimator • Type of property animator • Used for animating essential View properties • Position (or translation) • Rotation • Scale • Alpha • Can be used on custom View properties
Layer Caveats • Warning: redrawing a layer is *slower* than non-layer • DisplayLists will rebuild layers when necessary • Layering simple Views just hurts performance
ViewPropertyAnimator • Retrieved via View.animate() • Shortcut for simple animations • Better performance when manipulating multiple values of a View • Cons: no easy way to reverse • Cons: no way to group animations
Tween Animations • The original, so backwards compatible • Sometimes necessary • Fragment transactions • Limited to simple property changes • Not as rich as property animators
SurfaceView vs. TextureView • TextureView is API 4.0+ • TextureView only works in HW accelerated windows • TextureView can, itself, be animated • SurfaceView uses hack and acts weird • TextureView is not as fast as SurfaceView
Fragment Animations • Custom animations during Fragment transactions (adding/removing) • Limited to full-Fragment animations • Support library uses tween animations (instead of Animators)
Complex Fragment/ Activity Animations • Transition state • A --> A + B --> B • Invisible Fragments/transparent Activities • Single Activity, many Fragments/Views • ...Insert your solution here!
set directions • View methods: setLeft(), setRight(), setTop(), setBottom() • Skip layout during animations • Parent layout blows away values, may have to block