Android View 的尺寸大小变化的时候要求有一个过度的动画
来源:互联网 发布:淘宝店铺标志怎么没了 编辑:程序博客网 时间:2024/04/29 19:08
最近在项目里有个需求要求一个View 的尺寸大小变化的时候要求有一个过度的动画(view.getLayoutParams().height 100--->400)查看了一些资料后成功搞定,下面跟大家一起分享
解决的方法主要是继承Animation重写里面的几个方法,成功搞定
@Overrideprotected void applyTransformation(float interpolatedTime, Transformation t) { view.getLayoutParams().height = initialHeight + (int) ((targetHeight - initialHeight) * interpolatedTime); view.getLayoutParams().width = initialWidth + (int) ((targetWidth - initialWidth) * interpolatedTime); view.requestLayout();}@Overridepublic void initialize(int width, int height, int parentWidth, int parentHeight) { this.initialHeight = height; this.initialWidth = width; super.initialize(width, height, parentWidth, parentHeight);}@Overridepublic boolean willChangeBounds() { return true;}废话不多说,直接上代码
public class ViewSizeChangeAnimation extends Animation { int initialHeight; int targetHeight; int initialWidth; int targetWidth; View view; public ViewSizeChangeAnimation(View view, int targetHeight,int targetWidth) { this.view = view; this.targetHeight = targetHeight; this.targetWidth = targetWidth; } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { view.getLayoutParams().height = initialHeight + (int) ((targetHeight - initialHeight) * interpolatedTime); view.getLayoutParams().width = initialWidth + (int) ((targetWidth - initialWidth) * interpolatedTime); view.requestLayout(); } @Override public void initialize(int width, int height, int parentWidth, int parentHeight) { this.initialHeight = height; this.initialWidth = width; super.initialize(width, height, parentWidth, parentHeight); } @Override public boolean willChangeBounds() { return true; }}
最后在代码中调用
Animation animation = new ViewSizeChangeAnimation(imageView, isHide ? 100 : 1000, isHide ? 100 : 1000);animation.setDuration(500);imageView.startAnimation(animation);
好了,就这么简单,更多文章请移步学购网www.xuegou121.com
demo下载地址
0 0
- Android View 的尺寸大小变化的时候要求有一个过度的动画
- Android 4.0 对通知栏图标的尺寸有要求
- Android Icon的尺寸要求
- android view的width或者height变化的动画
- Android 有点击动画效果的View
- Android个屏幕的logo尺寸要求
- Android 中图标的尺寸要求
- 头像咋不支持gif动画的?还严格要求尺寸?
- android5.0的过度动画
- Android的View动画
- Android的View动画
- Android监听view尺寸变化
- 4.一个字体的随机颜色及有规律的大小变化
- 一个自定义的 View,支持显示下载进度,完成和结束的时候会有酷酷的动画。
- Android的过度绘制
- Android 系统prop属性+app的过度动画无法显示
- Android自定义View研究:View的大小
- Android自定义View研究:View的大小
- 第一次去面试
- leetcode Remove Duplicates from Sorted List II
- 如何在googleplay上发布应用?
- java企业级应用之术语篇
- 排序算法(2)-快速排序
- Android View 的尺寸大小变化的时候要求有一个过度的动画
- 属性动画 自定义属性
- 14.2.3 InnoDB Redo Log
- const 与define
- Android版本和API Level对应关系
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element
- 第十五周项目1:阅读程序,领会STL用法(1)
- 详解登录认证及授权--Shiro系列(一)
- log4j详细配置