当然可以。
只需编写自己的自定义动画并修改
LayoutParams动画视图的。在此示例中,动画为动画视图的 高度 设置了动画。当然,
对宽度进行动画处理也是可能的 。
它看起来像这样:
public class ResizeAnimation extends Animation { private int startHeight; private int deltaHeight; // distance between start and end height private View view; public ResizeAnimation (View v) { this.view = v; } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { view.getLayoutParams().height = (int) (startHeight + deltaHeight * interpolatedTime); view.requestLayout(); } public void setParams(int start, int end) { this.startHeight = start; deltaHeight = end - startHeight; } @Override public void setDuration(long durationMillis) { super.setDuration(durationMillis); } @Override public boolean willChangeBounds() { return true; }}在代码中, 创建一个新的Animation并将其应用于 要设置动画 的RelativeLayout :
RelativeLayout relativeLayout = (RelativeLayout) ((LinearLayout) view.findViewById(viewId)).getParent();// getting the layoutparams might differ in your application, it depends on the parent layoutRelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) relativeLayout.getLayoutParams();ResizeAnimation a = new ResizeAnimation(relativeLayout);a.setDuration(500);// set the starting height (the current height) and the new height that the view should have after the animationa.setParams(lp.height, newHeight);relativeLayout.startAnimation(a);



