Reputation: 17332
I have a linear layout with a couple text boxes, vertical. I want to add/remove one more text box (more specifically, set it to visible/gone). When this happens, I'd like to resize the parent view with an animation rather than just having it jump up and down. I've put a layout animation on the parent linear layout, and it animates the box in/out, but it appears to resize first, then animate the child, but that doesn't really solve the problem I'm having (looks nice, but you know).
Any thoughts?
Upvotes: 2
Views: 4415
Reputation: 16407
I know this question is pretty old, but I thought this would be a common problem before I run into it myself.
I took some inspiration from the code you had, but instead of using a separate class like this, what I did is to extend the LinearLayout class and added some methods to be able to animate it when the content changes (in my case, I am making some children views VISIBLE or GONE). Still working out a few details, but it works pretty well so far.
The good thing is that I can access / extend onMeasure method, so I do not have to do any estimation of the size after the animation, no matter what I have in my container, the animation will always go to the right place.
Hope that helps
Upvotes: 0
Reputation: 17332
I figured something out. I do it the "hard way" by resizing the container. The basic process is as follows:
Save the layout parameters Get the physical size of the container Set the layoutparams with the physical height Loop with a handler setting the size incrementally When its done, set the previous layout params
The code assume you're using a linear layout and a height of WRAP_CONTENT. If not, it would need an adjustment.
See blog
http://www.touchtech.co/blog/resize-animation/
Upvotes: 1