Search code examples
androidanimationandroid-animationviewgroupandroid-viewgroup

Animations are clipped to ViewGroup bounds in Android 4.3 and below?


I'm working on a custom ViewGroup which draws some animations in the dispatchDraw() method.

I came across this in my Google search: https://groups.google.com/forum/#!topic/android-developers/dZ0Yxjz3v7o

And I have set clipChildren="false" inside my XML to both the parent and the grandparent view of my custom ViewGroup. However, this fixed the clipping of the animations drawing on Android 4.3 and above. Android 4.0 - 4.3 still clips the View animations to its bounds.

Any help would be appreciated.


Solution

  • I've just done some trial and error and found a solution to my own problem :) (Don't you just love it when this happens??)

    Basically where I was calling my invalidate() on my custom view in order to draw the animation, I need to also call ((View) getParent()).invalidate() in order to invalidate the parent so that it forces a draw on it.

    I guess later versions of Android are smart about this, however for anything below 4.3 I needed to explicitly invalidate the parent in order to draw the animation beyond the bounds of my custom view.

    Hope this helps someone that ran into the same problem.