1

I am using code from here to display an expand/collapse animation of a LinearLayout: https://stackoverflow.com/a/5122460/458603

Animation quickEntryAnimation = new HeightAnimation(mQuickEntryArea, DisplayHelper.dpToPixel(200, this), mQuickEntryArea.getHeight() < 10);
quickEntryAnimation.setDuration(300);
mQuickEntryArea.startAnimation(quickEntryAnimation);
mQuickEntryArea.invalidate();

It collapses just fine, but whenever mQuickEntryArea's height is 0, it will only expand after something has caused the whole view to re-layout (e.g. tapping the screen). What's happening?

Community
  • 1
  • 1
manmal
  • 3,900
  • 2
  • 30
  • 42
  • Have you managed to solve it? I have exactyly the same problem. Thanks. – Yar Apr 27 '12 at 18:14
  • 1
    But anyway thanks to you mentioning height 0 I changed it to 1 and now it seems to work. – Yar Apr 27 '12 at 18:19
  • Haha yes that's what I did in the meantime :P I haven't looked into this project since then :) Please post if you find the solution! – manmal Apr 27 '12 at 18:31

1 Answers1

3

Try calling requestLayout() before starting the animation like this:

Animation quickEntryAnimation = new HeightAnimation(mQuickEntryArea, DisplayHelper.dpToPixel(200, this), mQuickEntryArea.getHeight() < 10);
quickEntryAnimation.setDuration(300);
mQuickEntryArea.requestLayout();
mQuickEntryArea.startAnimation(quickEntryAnimation);

At least for me, it solves the problem.

UPDATE: I Just checked another constellation were this did not work properly. I digged into the rendering code of the View class and noticed that there were multiple render procedures. The one activating animations is actually triggered by the view's parent. In case above solution does not work for you, try doing something like this:

mQuickEntryArea.startAnimation(quickEntryAnimation);
((ViewGroup) mQuickEntryArea.getParent()).invalidate();

Be aware that the parent does not have to be a ViewGroup!

Greetings, David

david.schreiber
  • 3,851
  • 2
  • 28
  • 46