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 View
s will stay directly below the content, instead of having a blank space?
I used the same technique as Andy here, and refined it so that it can be used for expanding and collapsing without glitches, also using a technique described here: https://stackoverflow.com/a/11426510/1317564
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.
Put the view in a layout if it's not and set
android:animateLayoutChanges="true"
for that layout.I used the same technique as Andy here has presented. I wrote my own Animation class for that, that animate the margin's value, causing the effect of the item to disappear/appear. It looks like this:
I have a full example that works on my blog post http://udinic.wordpress.com/2011/09/03/expanding-listview-items/