高度变化动画不顺畅

时间:2014-10-03 19:25:01

标签: android

这是我的高度变化动画

public class HeightAnimation extends Animation {
    private final int targetHeight;
    private final View view;
    private final boolean grow;
    private final int height;

    public HeightAnimation(View view, int targetHeight, boolean grow) {
        this.view = view;
        this.targetHeight = targetHeight;
        this.grow = grow;
        height = view.getHeight();
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        int newHeight;
        if (grow) {
            newHeight = (int) (height + (targetHeight - height) * interpolatedTime);
        } else {
            newHeight = (int) (height + (targetHeight - height) * interpolatedTime);
        }
        view.getLayoutParams().height = newHeight;
        view.requestLayout();
    }

    @Override
    public void initialize(int width, int height, int parentWidth,
                           int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
    }

    @Override
    public boolean willChangeBounds() {
        return true;
    }
}

问题是,当它运行时它是不是很平滑它看起来是跳过那里来平滑这个吗?

 HeightAnimation animation = new HeightAnimation(mSwitcher, 0, false);
 animation.setDuration(300);
 mSwitcher.startAnimation(animation);

0 个答案:

没有答案
相关问题