如何设置版式的宽度和高度的动画?

如何设置版式的宽度和高度的动画?,第1张

如何设置版式的宽度和高度的动画

当然可以。

只需编写自己的自定义动画并修改

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


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5587196.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-14
下一篇2022-12-14

发表评论

登录后才能评论

评论列表(0条)

    保存