问题
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;
}
回答1:
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.
来源:https://stackoverflow.com/questions/22645298/android-objectanimator-expand-collapse-from-top-to-bottom-animation