Android扩展动画最初缩小然后扩展,只想扩展

时间:2013-11-14 04:42:21

标签: android android-layout android-animation

我有一个自定义动画,我正在尝试将其应用于RelativeLayout以扩展其高度。当我开始动画时,它最初缩小到0高度然后去。

public class ExpandAnimation extends Animation {

int startHeight;
View mView;

public ExpandAnimation(View view) {
    this.mView = view;
    this.startHeight = view.getHeight();
}

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    int newHeight;
    int targetHeight = (int) startHeight * 2;

    newHeight = (int) (startHeight + (targetHeight - startHeight) * interpolatedTime);

    mView.getLayoutParams().height = newHeight;

    mView.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 a = new ExpandAnimation(rowView);
a.setInterpolator(new AccelerateInterpolator());
a.setDuration(this.getResources().getInteger(R.integer.animation_duration));
rowView.setAnimation(a);
rowView.startAnimation(a);                  

0 个答案:

没有答案