Search code examples
androidanimationobjectanimator

Android expand view animation


I have a bottomBar that i would like to expand. I think i know how to do it with animations.

But according to What is the difference between an Animator and an Animation?

If i use old animations. Then the buttons would not be relocated. Only visually.

How could i achieve this with Animators.

What i am trying to achieve

enter image description here

So could someone nudge me in the right direction.


Solution

  • This solved my problem.

        public static ValueAnimator slideAnimator(int start, int end, final View view, int duration) {
        ValueAnimator animator = ValueAnimator.ofInt(start, end);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int val = (Integer) valueAnimator.getAnimatedValue();
                ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
                layoutParams.height = val;
                view.setLayoutParams(layoutParams);
            }
        });
        animator.setDuration(duration);
        return animator;
    }
    

    Credit to: Android property animation: how to increase view height?