Android动画跳到最后

时间:2015-08-03 07:07:57

标签: android android-animation

您好我想尝试一个简单的ListView扩展animationanimation正在运行,但有时会跳到最后,然后恢复animation

GIF of the problem

这是动画类的代码:

public class DropDownAnimation extends Animation {
private int targetHeight;
private View view;
private boolean down;

public DropDownAnimation(View view, int targetHeight, boolean down) {
    this.view = view;
    this.targetHeight = targetHeight;
    this.down = down;
}

public DropDownAnimation(View view, int targetHeight) {
    this.view = view;
    this.targetHeight = targetHeight;
    this.setDuration(350);
    if(view.getVisibility() == View.INVISIBLE)
        down = true;
    else
        down = false;
}

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    super.applyTransformation(interpolatedTime,t);
    int newHeight;
    if (down) {
        newHeight = (int) (targetHeight * interpolatedTime);
        view.setVisibility(View.VISIBLE);
    } else {
        newHeight = (int) (targetHeight * (1 - interpolatedTime));
        view.setVisibility(View.INVISIBLE);
    }
    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;
}
}

Animation被称为:

DropDownAnimation dropDownAnimation = new DropDownAnimation(toolbar,expandedHeight);
            toolbar.startAnimation(dropDownAnimation);
            View parent = (View)test.getParent();
            parent.invalidate();

0 个答案:

没有答案