原理是继承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伸缩动画.的更多相关文章

  1. RookeyFrame 隐藏 首次加载菜单 的伸缩动画

    一进入系统,然后点击菜单“系统管理”,会看到展开的“系统设置”菜单,又缩回去了,每次都会有(处女座看到就想改). 隐藏这个动画的JS:jquery.easyui.min.js,这个JS里面有个方法“_ ...

  2. Android仿支付宝高顶部功能条伸缩动画

    参考:https://blog.csdn.net/aqi00/article/details/72621176

  3. Android动画学习(二)——Tween Animation

    前两天写过一篇Android动画学习的概述,大致的划分了下Android Animation的主要分类,没有看过的同学请移步:Android动画学习(一)——Android动画系统框架简介.今天接着来 ...

  4. 初识android中的动画

    动画效果可以大大提高界面的交互效果,因此,动画在移动开发中的应用场景较为普遍.掌握基本的动画效果在成熟的软件开发中不可或缺.除此之外,用户对于动画的接受程度远高于文字和图片,利用动画效果可以加深用户对 ...

  5. Android中的动画机制

          1 逐帧动画   逐帧动画 就是一系列的图片按照一定的顺序展示的过程.   逐帧动画很简单, 只需要在drawable中或者anim中定义一个Animation-list 其中包含多个it ...

  6. Android 动画分类

    一:Tween Animation 动画类型 下面先来看看Android提供的动画类型.Android的animation由四种类型组成 在XML文件中: alpha        渐变透明度动画效果 ...

  7. android 最详细的动画大全,包括如何在代码和在XML中使用

    一.动画类型 Android的animation由四种类型组成:alpha.scale.translate.rotate XML配置文件中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画 ...

  8. 动画_ _ Android应用开发之所有动画使用详解

    转载: http://blog.csdn.net/yanbober/article/details/46481171 题外话:有段时间没有更新博客了,这篇文章也是之前写了一半一直放在草稿箱,今天抽空把 ...

  9. 动画---图形图像与动画(三)Animation效果的XML实现

    使用XML来定义Tween Animation 动画的XML文件在工程中res/anim目录,这个文件必须包含一个根元素,可以使<alpha><scale> <trans ...

随机推荐

  1. php 即时输出

    <?phpset_time_limit(0);ob_end_clean();ob_implicit_flush(1);$i=0;while ( $i>=0 ) { sleep(1); ec ...

  2. ==、equals、hashCode区别?

    [==.equals().hashCode()区别?] 1)== 运算符用来比较两个变量的值是否相等. 即该运算符用于比较变量对应得内存中所存储的数值是否相同,要比较两个基本类型的数据或两个引用变量是 ...

  3. DOM操作-遍历一个元素的所有属性

    代码: <!DOCTYPE html> <html> <head> <title>遍历打印一个元素的所有属性</title> <met ...

  4. HDU 2544 最短路(dijkstra+邻接矩阵)

    ( ̄▽ ̄)" #include<iostream> #include<cstdio> using namespace std; const int INF=10e7; ...

  5. PAXOS may not terminate

    It’s easy to see that Paxos does have a failure mode. When two proposers are active at the same time ...

  6. unlinking

    When a file name is deleted from the directory tree, the file name's connection to the inode number ...

  7. android动态LinearLayout

    在onCreate函数中: mLinearlayout= new LinearLayout(this); mLinearlayout.setOrientation(LinearLayout.VERTI ...

  8. Java良葛格 学习笔记

    学习一个新的事物时,如果遇到一些概念无法很快理解,这可能是因为要理解概念会需要其它概念先建立起来,所以先暂时放下这个疑问也是一个学习方法,称之为“存疑” ,在以后的学习过程中待必要的概念学会后,目前的 ...

  9. 好用的API文档--在线版

    安卓在线api http://www.android-doc.com/reference/packages.html

  10. 上传下载文件, 同时部署在webapps下, 而不是项目下,防止重新部署tomcat, 上传文件消失

    前端上传 <a href='javascript:upload("+data[i].id+")' title='Upload Report'> <img src= ...