
I’m animating a view using TranslateAnimation in order to achieve a drop down view animation. The problem I’m facing is that size of the container does not increase after the animation has finished.
Please check the image and snippet code:
TranslateAnimation animation = new TranslateAnimation(0.0f, 0.0f, top, top + px);
animation.initialize(mDropDownLayout.getWidth(),mDropDownLayout.getHeight(), parentLayout.getWidth(), parentLayout.getHeight());
animation.setDuration(2000);
animation.setFillEnabled(true);
animation.setFillBefore(true);
mDropDownLayout.startAnimation(animation);
The result I’m trying to achieve is that the container’s height should increase as the as the animated view is translating, progressively.
UPDATE: Also, the animated view is moved only visually, not structurally.
Finally, I got this. Android has two types of animation packages, View animation(android.view.animation) and Property animation(android.animation). The latter one was introduced with Honeycomb.
I tried animating first with view animation but in vain, because I was not able to move the layout structure to the visual position after the animation was completed.
Then, I tried it with the Property Animation and I was able to achieve the desired results.
I highly recommend using property animation and you can also use it for api levels below 11 by using NineOldAndroids library.
I’ve added the demo project on github. Check it here
NOTE : You will need NineOldAndroids library in order to run this demo on all api levels.