0

I'm trying to animate the height of a ConstraintLayout using the Animation class, and the setDuration method doesn't seem to be working. The height is just instantly changed to the desired height value. I've seen posts about animations being disabled in the developer options, but that's not the problem, it's set to 1x. Anyway, code is below:

    public static void scaleUp() {

    Animation animation = new Animation() {

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) profileLayout.getLayoutParams();

            // modify your layout params here
            params.height = 10;

            profileLayout.setLayoutParams(params);

        }
    };

        animation.setDuration(300); // in ms
        profileLayout.startAnimation(animation);
}

2 Answers2

1

Possible Solutions:

  1. Answered Here
  2. Medium Article About Animating
LinuxDevil
  • 36
  • 3
  • Thanks for the tips. I should of decreased the speed just to remove that as a possible solution. I've tried setting it to multiple seconds and no changes. I think the medium article looks really promising, but I'm getting an error "Lambda expressions are not supported at language level '7'" on the code: `slideAnimator.addUpdateListener(animation1 -> { Integer value = (Integer) animation1.getAnimatedValue(); view.getLayoutParams().height = value.intValue(); view.requestLayout(); });` – Paul Campbell Aug 15 '21 at 21:47
  • Welcome, for the "Lambda expressions are not supported at language level '7'" do this: https://stackoverflow.com/a/22704620/6552901 – LinuxDevil Aug 15 '21 at 21:53
1
  1. Instead of params.height = 10; use params.height = (int)(10.0 * interpolatedTime).
  2. Append profileLayout.requestLayout(); at the end of your applyTransformation method. This is used to update the layout on a screen.