首页 > 解决方案 > setDuration 在动画类中不起作用

问题描述

我正在尝试使用 Animation 类为 ConstraintLayout 的高度设置动画,而 setDuration 方法似乎不起作用。高度会立即更改为所需的高度值。我在开发人员选项中看到过有关禁用动画的帖子,但这不是问题,它设置为 1x。无论如何,代码如下:

    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);
}

标签: android

解决方案


可能的解决方案:

  1. 在这里回答
  2. 关于动画的中篇文章

推荐阅读