1
如何在點擊時將視圖的高度更改爲match_parent?設置高度視圖以配合父母與動畫在Android中
public class ResizeAnimation extends Animation {
final int startHeight;
final int targetHeight;
private final boolean isOpen;
View view;
public ResizeAnimation(View view, int height, boolean isOpen) {
this.view = view;
this.targetHeight = height;
this.isOpen = isOpen;
startHeight = view.getHeight();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newHeight;
if (isOpen) {
newHeight = (int) (startHeight + (targetHeight - startHeight) * interpolatedTime);
} else {
newHeight = (int) (startHeight + targetHeight * 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;
}
}
ResizeAnimation resizeAnimation = new ResizeAnimation(view, MATCH_PARENT, false);
resizeAnimation.setDuration(500);
view.startAnimation(resizeAnimation);