您好我想尝试一个简单的ListView
扩展animation
。 animation
正在运行,但有时会跳到最后,然后恢复animation
。
这是动画类的代码:
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();