栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

当然可以。

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

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


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/596005.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号