0

I initialize ObjectAnimator like this;

ObjectAnimator anim = ObjectAnimator.ofFloat(view, "translationY", 0f, view.getHeight());

But when the first time animation runs, view.getHeight() method returns 0. So it does not animate. Second time i run the animation, it animates right. Is there a way to translate views relative to their width or height properly?

ferpar1988
  • 596
  • 2
  • 5
  • 17
  • maybe you have your view set after the anim object? if it's empty, it may have 0 height, and then you ex. add a picture to it and it gets different height – cyborg86pl Mar 19 '14 at 08:40
  • This answer may be helpful. http://stackoverflow.com/questions/18268915/views-getwidth-and-getheight-returning-0?answertab=active#tab-top – cyborg86pl Mar 19 '14 at 08:45
  • Initial visibility of the view is "gone". I make the view visible when animation start. But this time getHeight() method returns 0. – ferpar1988 Mar 19 '14 at 08:48
  • do you make it visible before or after animation starts? – cyborg86pl Mar 19 '14 at 08:49
  • I tried. Still getHeight() returns 0. – ferpar1988 Mar 19 '14 at 08:55
  • what about that? http://stackoverflow.com/questions/6145001/getwidth-and-getheight-are-returning-a-zero?answertab=active#tab-top – cyborg86pl Mar 19 '14 at 09:03
  • 1
    Thank you. Found the answer calling view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); and after view.getMeasuredHeight() returns the right height value. – ferpar1988 Mar 19 '14 at 10:02

0 Answers0