android objectanimator expand/collapse from top to bottom animation?

梦想的初衷 提交于 2020-01-16 21:58:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!