androidandroid-animationobjectanimator

android objectanimator expand/collapse from top to bottom animation?


I've been trying different approaches to get the expand/collapse animation with object animator but none of them so far worked.

I have used this solution and it works, but when I read the documentation it says it's more preferred to use animator to permanently animate objects rather than animation.

Problem with my code is that it always starts from top of the view, and yet I need to expand/collapse the view from bottom.

here is my code:

public boolean collapse( View view, int start, int end )
{
    AnimatorSet set = new AnimatorSet();
    ObjectAnimator a = ObjectAnimator.ofFloat( view, "translationY", start, end );
    set.play( a );
    set.setDuration( 3000L );
    set.setInterpolator( new LinearInterpolator() );
    set.addListener( new AnimatorListenerAdapter()
    {
        @Override
        public void onAnimationEnd( Animator animation )
        {
        }
    } );
    set.start();
    return true;
}

Solution

  • Trying using an ObjectAnimator.ofInt and use the property name of bottom. That will animate starting on the bottom of the view. TranslationY corresponds to the top of the view.