1

I want to click a button and have certain View containers change size smoothly/transitionally. Can this be done in Android?

KaliMa
  • 1,970
  • 6
  • 26
  • 51

1 Answers1

0

If by view container you mean ViewGroup you can use a ValueAnimator. It's a simple timing engine that you can use to do animation.

For example if you want to animate a change of height for a RelativeLayout rl to finalHeight from startHeight in 400ms you can do :

ValueAnimator va = ValueAnimator.ofFloat(0f, 1f);
va.setDuration(400);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                Float value = (Float) animation.getAnimatedValue();
                rl.height = (int) (startHeight + (finalHeight - startHeight) * value);
                rl.requestLayout();
            }
        });

You can use different interpolator and customize the ValueAnimator to do some really nice effect. http://developer.android.com/reference/android/animation/ValueAnimator.html

Gauthier
  • 4,798
  • 5
  • 34
  • 44