StretchAnimation伸缩动画.
原理是继承animation 然后改变他的margintop 和marginbottom 形成2个效果
ExpandTopAnimation
public class ExpandTopAnimation extends Animation {
private View mAnimatedView;
private LayoutParams mViewLayoutParams;
private int mMarginStart, mMarginEnd;
private boolean mIsVisibleAfter = false;
private boolean mWasEndedAlready = false; public ExpandTopAnimation(View view, int duration) { setDuration(duration);
mAnimatedView = view;
mViewLayoutParams = (LayoutParams) view.getLayoutParams(); // if the bottom margin is 0,
// then after the animation will end it'll be negative, and invisible.
mIsVisibleAfter = (mViewLayoutParams.topMargin == 0); mMarginStart = mViewLayoutParams.topMargin;
mMarginEnd = (mMarginStart == 0 ? (0 - view.getHeight()) : 0); view.setVisibility(View.VISIBLE);
} @Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t); if (interpolatedTime < 1.0f) { // Calculating the new bottom margin, and setting it
mViewLayoutParams.topMargin = mMarginStart
+ (int) ((mMarginEnd - mMarginStart) * interpolatedTime); // Invalidating the layout, making us seeing the changes we made
mAnimatedView.requestLayout(); // Making sure we didn't run the ending before (it happens!)
} else if (!mWasEndedAlready) {
mViewLayoutParams.topMargin = mMarginEnd;
mAnimatedView.requestLayout(); if (mIsVisibleAfter) {
mAnimatedView.setVisibility(View.GONE);
}
mWasEndedAlready = true;
}
}
}
ExpandBottomAnimation
public class ExpandBottomAnimation extends Animation {
private View mAnimatedView;
private LayoutParams mViewLayoutParams;
private int mMarginStart, mMarginEnd;
private boolean mIsVisibleAfter = false;
private boolean mWasEndedAlready = false; public ExpandBottomAnimation(View view, int duration) { setDuration(duration);
mAnimatedView = view;
mViewLayoutParams = (LayoutParams) view.getLayoutParams(); // if the bottom margin is 0,
// then after the animation will end it'll be negative, and invisible.
mIsVisibleAfter = (mViewLayoutParams.bottomMargin == ); mMarginStart = mViewLayoutParams.bottomMargin;
mMarginEnd = (mMarginStart == ? ( - view.getHeight()) : ); view.setVisibility(View.VISIBLE);
} @Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t); if (interpolatedTime < 1.0f) { // Calculating the new bottom margin, and setting it
mViewLayoutParams.bottomMargin = mMarginStart
+ (int) ((mMarginEnd - mMarginStart) * interpolatedTime); // Invalidating the layout, making us seeing the changes we made
mAnimatedView.requestLayout(); // Making sure we didn't run the ending before (it happens!)
} else if (!mWasEndedAlready) {
mViewLayoutParams.bottomMargin = mMarginEnd;
mAnimatedView.requestLayout(); if (mIsVisibleAfter) {
mAnimatedView.setVisibility(View.GONE);
}
mWasEndedAlready = true;
}
}
}
MainActivity
public class MainActivity extends Activity { private ListView lv; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.lv); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.lv_item); for (int i = 0; i < 30; i++) {
adapter.add("wiki"+i);
} lv.setAdapter(adapter); } public void top(View view){
// trans(lv); ExpandTopAnimation ea = new ExpandTopAnimation(lv, 200);
view.startAnimation(ea);
} public void bottom(View view){ ExpandBottomAnimation ea = new ExpandBottomAnimation(lv, 200);
view.startAnimation(ea);
} }
top效果
bottom效果
StretchAnimation伸缩动画.的更多相关文章
- RookeyFrame 隐藏 首次加载菜单 的伸缩动画
一进入系统,然后点击菜单“系统管理”,会看到展开的“系统设置”菜单,又缩回去了,每次都会有(处女座看到就想改). 隐藏这个动画的JS:jquery.easyui.min.js,这个JS里面有个方法“_ ...
- Android仿支付宝高顶部功能条伸缩动画
参考:https://blog.csdn.net/aqi00/article/details/72621176
- Android动画学习(二)——Tween Animation
前两天写过一篇Android动画学习的概述,大致的划分了下Android Animation的主要分类,没有看过的同学请移步:Android动画学习(一)——Android动画系统框架简介.今天接着来 ...
- 初识android中的动画
动画效果可以大大提高界面的交互效果,因此,动画在移动开发中的应用场景较为普遍.掌握基本的动画效果在成熟的软件开发中不可或缺.除此之外,用户对于动画的接受程度远高于文字和图片,利用动画效果可以加深用户对 ...
- Android中的动画机制
1 逐帧动画 逐帧动画 就是一系列的图片按照一定的顺序展示的过程. 逐帧动画很简单, 只需要在drawable中或者anim中定义一个Animation-list 其中包含多个it ...
- Android 动画分类
一:Tween Animation 动画类型 下面先来看看Android提供的动画类型.Android的animation由四种类型组成 在XML文件中: alpha 渐变透明度动画效果 ...
- android 最详细的动画大全,包括如何在代码和在XML中使用
一.动画类型 Android的animation由四种类型组成:alpha.scale.translate.rotate XML配置文件中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画 ...
- 动画_ _ Android应用开发之所有动画使用详解
转载: http://blog.csdn.net/yanbober/article/details/46481171 题外话:有段时间没有更新博客了,这篇文章也是之前写了一半一直放在草稿箱,今天抽空把 ...
- 动画---图形图像与动画(三)Animation效果的XML实现
使用XML来定义Tween Animation 动画的XML文件在工程中res/anim目录,这个文件必须包含一个根元素,可以使<alpha><scale> <trans ...
随机推荐
- HttpWatch工具简介及使用技巧(转载)
一 概述: HttpWatch强大的网页数据分析工具.集成在Internet Explorer工具栏.包括网页摘要.Cookies管理.缓存管理.消息头发送/接受.字符查询.POST 数据和目录管理功 ...
- php 上传缩放图片
有时上传图片时因为图片太大了,不仅占用空间,消耗流量,而且影响浏(图片的尺寸大小不一).下面分享一种等比例不失真缩放图片的方法,这样,不管上传的图片尺有多大,都会自动压缩到我们设置尺寸值的范围之内.经 ...
- JavaScript高级程序设计:第十四章
第十四章 一.表单的基础知识 在HTML中,表单是由<form>元素来表示的,而在javascript中,表单对应的则是HTMLFormElement类型.HTMLFormElement继 ...
- Boxes in a Line(移动盒子)
You have n boxes in a line on the table numbered 1 . . . n from left to right. Your task is to sim ...
- ios中的关键词retain release
内存分析 在函数中只要用new alloc copy 这样的分配空间时 则计算器retain就要为一 每调用一次就要加一 在.m文件中引用手动计数时 一定要调用[super dealloc]这 ...
- ORACLE里锁有以下几种模式,v$locked_object,locked_mode【转】
ORACLE里锁有以下几种模式:0:none1:null 空2:Row-S 行共享(RS):共享表锁,sub share 3:Row-X 行独占(RX):用于行的修改,sub exclusive 4: ...
- [code]最长回文子串
分析: 不能用scanf("%s"),因为碰到空格或者Tab就会停下来. 解决输入中有空格 方法一:使用fgetc(fin),读取一个打开的文件fin,读取一个字符,然后返回一个i ...
- ios中点语法、property跟synthesize用法
一:OC中得点语法 1> 点语法的基本使用: ·使用 对象.成员变量 可以实现设置成员变量值,和获取成员变量的值 2> 点语法的本质 (点语法是Xcode编译器自己帮我们完成的一个 ...
- icecap录屏gif
百度云下载地址:http://pan.baidu.com/s/1jIeyb4q 之前写博客,只有文字,有些效果看不出来.有了这个gif录屏工具方便很多哦,嘿嘿
- 安卓常用 widget
验证码 public class SpinnerImg extends ImageView { /** * 完成选择后启动另外一个spinner */ private ItemListener ite ...