2

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

0 に答える 0