I want to make an Animation for when a View gets it’s visibility set to GONE. Instead of just dissapearing, the View should ‘collapse’. I tried this with a ScaleAnimation but then the View is collapse, but the layout will only resize it’s space after (or before) the Animation stops (or starts).
How can I make the Animation so that, while animating, the lower Views will stay directly below the content, instead of having a blank space?
There doesn’t seem to be an easy way to do this through the API, because the animation just changes the rendering matrix of the view, not the actual size. But we can set a negative margin to fool LinearLayout into thinking that the view is getting smaller.
So I’d recommend creating your own Animation class, based on ScaleAnimation, and overriding the “applyTransformation” method to set new margins and update the layout. Like this…
The usual caveat applies: because we are overriding a protected method (applyTransformation), this is not guaranteed to work in future versions of Android.