0

For my current project I'm building a pulldown view with a handle and a content. When I move the handle by dragging it everything is fine. Then I let it go and start an animation to fully open or close the pulldown.

First: without the animation in it everything is fine, but off course not that smooth...

So I've added this for the animation:

    ObjectAnimator animHandle = ObjectAnimator.ofFloat(mHandleContainer, "y", newHandlePosition);
    ObjectAnimator animContent = ObjectAnimator.ofFloat(mContent, "y", newContentPosition);
    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(animHandle, animContent);
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.setDuration(MAX_ANIMATION_DURATION);
    animatorSet.start();

Everything is just fine utill here.

But then, when I press the handle (mHandleContainer) again, I want to know where the handle is positioned so I do a

    mHandleContainer.getTop()

And that is where it all goes wrong. When I initialize the custom component I set the top of the handle to 0. So far so good, then I start dragging, when I let go I see that I will animate to a position of 1134 pixels. Which is fine (meaning the pull down will be entirely open).

But then I press the handle again and get the top (getTop()) and it still returns me 0.

What I want is that my view's getTop() function returns me 1134 again.

Is that possible?

Or should I do something in the onAnimationEnd method of my AnimatorListener? I already tried to do a mHandleContainer.layout(..) in there and then my getTop() is ok, but then my layout is screwed...

And tricks here for letting the animation end on the correct position (as it does) and persist the position in the view?

I already had a look on SO (and Google) but didn't find something useful. The only thing close to my problem that I could find was this: NineOldAndroids, not clickable view after rotation or move But didn't help either...

Community
  • 1
  • 1
dirkvranckaert
  • 1,364
  • 1
  • 17
  • 30

2 Answers2

0

This is because your are animating the "y" property while trying to read the property top, and they aren't the same. Top is the top position of the view relative to its parent. Y is the visual y position of the view which is equivalent to translationY + the current top property.

So in your case:

  1. Either animate "top" like this:

    ObjectAnimator animHandle = ObjectAnimator.ofFloat(mHandleContainer, "top", 200);
    

    And read it via

    mHandleContainer.getTop()
    
  2. Or "y":

    ObjectAnimator animHandle = ObjectAnimator.ofFloat(mHandleContainer, "y", 200);
    

    And read it via

    mHandleContainer.getY();
    
Gomino
  • 12,127
  • 4
  • 40
  • 49
0

I did solve the issue using the basic ValueAnimator which each time called my custom drawing method for moving all my views.

dirkvranckaert
  • 1,364
  • 1
  • 17
  • 30